'American Express', 'length' => '15', 'prefixes' => '34,37', 'checkdigit' => true ), array ('name' => 'Diners Club Carte Blanche', 'length' => '14', 'prefixes' => '300,301,302,303,304,305', 'checkdigit' => true ), array ('name' => 'Diners Club', 'length' => '14,16', 'prefixes' => '305,36,38,54,55', 'checkdigit' => true ), array ('name' => 'Discover', 'length' => '16', 'prefixes' => '6011,622,64,65', 'checkdigit' => true ), array ('name' => 'Diners Club Enroute', 'length' => '15', 'prefixes' => '2014,2149', 'checkdigit' => true ), array ('name' => 'JCB', 'length' => '16', 'prefixes' => '35', 'checkdigit' => true ), array ('name' => 'Maestro', 'length' => '12,13,14,15,16,18,19', 'prefixes' => '5018,5020,5038,6304,6759,6761', 'checkdigit' => true ), array ('name' => 'MasterCard', 'length' => '16', 'prefixes' => '51,52,53,54,55', 'checkdigit' => true ), array ('name' => 'Solo', 'length' => '16,18,19', 'prefixes' => '6334,6767', 'checkdigit' => true ), array ('name' => 'Switch', 'length' => '16,18,19', 'prefixes' => '4903,4905,4911,4936,564182,633110,6333,6759', 'checkdigit' => true ), array ('name' => 'Visa', 'length' => '13,16', 'prefixes' => '4', 'checkdigit' => true ), array ('name' => 'Visa Electron', 'length' => '16', 'prefixes' => '417500,4917,4913,4508,4844', 'checkdigit' => true ), array ('name' => 'LaserCard', 'length' => '16,17,18,19', 'prefixes' => '6304,6706,6771,6709', 'checkdigit' => true ) ); $ccErrorNo = 0; $ccErrors [0] = "Unknown card type"; $ccErrors [1] = "No card number provided"; $ccErrors [2] = "Credit card number has invalid format"; $ccErrors [3] = "Credit card number is invalid"; $ccErrors [4] = "Credit card number is wrong length"; // Establish card type $cardType = -1; for ($i=0; $i= 0; $i--) { // Extract the next digit and multiply by 1 or 2 on alternative digits. $calc = $cardNo{$i} * $j; // If the result is in two digits add 1 to the checksum total if ($calc > 9) { $checksum = $checksum + 1; $calc = $calc - 10; } // Add the units element to the checksum total $checksum = $checksum + $calc; // Switch the value of j if ($j ==1) {$j = 2;} else {$j = 1;}; } // All done - if checksum is divisible by 10, it is a valid modulus 10. // If not, report an error. if ($checksum % 10 != 0) { $errornumber = 3; $errortext = $ccErrors [$errornumber]; return false; } } // The following are the card-specific checks we undertake. // Load an array with the valid prefixes for this card $prefix = explode(',',$cards[$cardType]['prefixes']); // Now see if any of them match what we have in the card number $PrefixValid = false; for ($i=0; $i