Here's the code for my cc_validation.php - the only thing I can guess is that when 15 digits are entered instead of 16, it comes back with the numbers not adding up to that kind of card??? I'm stumped. Can someone out there help or point me to help? Thanks.
Osmyrna
<?php
/*
$Id: cc_validation.php,v 1.1 2002/11/01 02:13:21 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright © 2002 osCommerce
Released under the GNU General Public License
*/
// start the card recognition and acceptance
class cc_validation {
var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year;
// Remove any non numeric characters.
function cleancc($number) {
return ereg_replace('[^0-9]', '', $number);
}
function validate($number, $expiry_m, $expiry_y) {
$this->cc_number = $number;
// could not get the strip non numerics to work but left the function in and commented out the function call
// $Number = cc_validation::cleancc($number);
$Number = $number;
// 4 number and 6 number checks
$NumberLeft4 = substr($Number, 0, 4);
$NumberLeft6 = substr($Number, 0, 6);
$NumberLength = strlen($Number);
if ( strtolower(CC_VAL) == 'true' ) {
//empty these variables just to be sure
$ShouldLength2='';
$ShouldLength3='';
// Diners Club
if (ereg('^3(0[0-5].{11}|[68].{12})$', $this->cc_number)) {
$this->cc_type = 'Diners Club';
$ShouldLength = 14;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_DINERSCLUB) != 'true' ) {
return -5;
}
// American Express
} elseif (ereg('^3[47].{13}$', $this->cc_number)) {
$this->cc_type = 'American Express';
$ShouldLength = 15;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_AMERICANEXPRESS) != 'true' ) {
return -5;
}
// Carte Blanche
} elseif ( ($NumberLeft4 >= 3890) && ($NumberLeft4 <= 3899) ) {
$this->cc_type = 'Carte Blanche';
$ShouldLength = 14;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_CARTBLANCHE) != 'true' ) {
return -5;
}
// Australian Bankcard
} elseif (ereg('^5610.{12}$', $this->cc_number)) {
$this->cc_type = 'Australian BankCard';
$ShouldLength = 16;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_OZBANKCARD) != 'true' ) {
return -5;
}
// Discover/Novus
} elseif (ereg('^6011.{12}$', $this->cc_number)) {
$this->cc_type = 'Discover/Novus';
$ShouldLength = 16;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_DISCOVERNOVUS) != 'true' ) {
return -5;
}
// Mastercard
} elseif (ereg('^5[1-5].{14}$', $this->cc_number)) {
$this->cc_type = 'Master Card';
$ShouldLength = 16;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_MASTERCARD) != 'true' ) {
return -5;
}
// JCB
} elseif (ereg('^(3.{15}|(2131|1800).{11})$', $this->cc_number)) {
$this->cc_type = 'JCB';
$ShouldLength = 16;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_JCB) != 'true' ) {
return -5;
}
// Visa
} elseif (ereg('^4(.{12}|.{15})$', $this->cc_number)) {
$this->cc_type = 'Visa';
$ShouldLength = 16;
$ShouldLength2 = 13;
if ( strtolower(MODULE_PAYMENT_CC_ACCEPT_VISA) != 'true' ) {
return -5;
}
} else {
return -1;
}
// function to check the number length
// Is the number the right length?
if ( !( ($NumberLength == $ShouldLength)
|| ( !(empty($ShouldLength2)) && ($NumberLength == $ShouldLength2) )
|| ( !(empty($ShouldLength3)) && ($NumberLength == $ShouldLength3) ) ) ) {
return -6;
}
} else {
$this->cc_type = 'CC';
}
if ( strtolower(CC_BLACK) == 'true' ) {
// Blacklist check
$card_info = tep_db_query("select c.blacklist_card_number from " . TABLE_BLACKLIST . " c where c.blacklist_card_number = '" . $Number . "'");
if (tep_db_num_rows($card_info) != 0) { // card not found in database
return -7;
}
}
// checks the expiry just in case the javascript does not
if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) {
$this->cc_expiry_month = $expiry_m;
} else {
return -2;
}
$current_year = date('Y');
$expiry_y = substr($current_year, 0, 2) . $expiry_y;
if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) {
$this->cc_expiry_year = $expiry_y;
} else {
return -3;
}
if ($expiry_y == $current_year) {
if ($expiry_m < date('n')) {
return -4;
}
}
return $this->is_valid();
}
function is_valid() {
$cardNumber = strrev($this->cc_number);
$numSum = 0;
for ($i=0; $i<strlen($cardNumber); $i++) {
$currentNum = substr($cardNumber, $i, 1);
// Double every second digit
if ($i % 2 == 1) {
$currentNum *= 2;
}
// Add digits of 2-digit numbers together
if ($currentNum > 9) {
$firstNum = $currentNum % 10;
$secondNum = ($currentNum - $firstNum) / 10;
$currentNum = $firstNum + $secondNum;
}
$numSum += $currentNum;
}
// If the total has no remainder it's OK
return ($numSum % 10 == 0);
}
}
?>