This example describes a PHP implementation that validates all types of credit card classes. Share to everyone for your reference. Specifically as follows:
This PHP class is complete, can be used to verify a variety of credit cards, credit card number of the general rules of the verification, while the different types of credit cards are targeted identification.
The code accepts a credit card number and a valid date, and returns True if both are valid, otherwise it returns false.
This plugin accepts the following parameters:
$number A string representing the credit card number
$expiry credit Card valid date, in 07/12 or 0712 format
<?php//Plug-in 32:validate credit card//The is a executable example with additional code supplied/to obtain
Just the Plug-ins please click on the Download link $card = "4567 1234 5678 9101";
$exp = "06/11";
echo "Validating: $card: $exp <br>";
$result = PIPHP_VALIDATECC ($card, $exp);
if ($result!= FALSE) echo "card validated";
else echo "card did not validate"; function Piphp_validatecc ($number, $expiry) {//Plug-in 32:validate credit card////This Plug-in accepts a Credi T card number and/a expiry date and returns TRUE or FALSE,//depending on whether the details pass date// Checksum validation. The arguments required//are:///$number: Credit card number//$expiry: expiry date in the form://07
/12 or 0712 (for July) $number = preg_replace ('/[^\d]/', ', $number);
$expiry = preg_replace ('/[^\d]/', ', ', $expiry);
$left = substr ($number, 0, 4);
$cclen = strlen ($number);
$chksum = 0; Diners Club IF ($left >= 3000) && ($left <= 3059) | |
($left >= 3600) && ($left <= 3699) | |
($left >= 3800) && ($left <= 3889)) if ($cclen!=) return FALSE;
JCB if ($left >= 3088) && ($left <= 3094) | |
($left >= 3096) && ($left <= 3102) | |
($left >= 3112) && ($left <= 3120) | |
($left >= 3158) && ($left <= 3159) | |
($left >= 3337) && ($left <= 3349) | |
($left >= 3528) && ($left <= 3589)) if ($cclen!=) return FALSE;
American Express ElseIf (($left >= 3400) && ($left <= 3499) | |
($left >= 3700) && ($left <= 3799)) return FALSE if ($cclen!=)
Carte Blanche ElseIf (($left >= 3890) && ($left <=)) if ($cclen 3899) return FALSE; Visa ElseIf (($left >= 4000) && ($left <= 4999) if ($cclen!= && $cclen!=) return FA
LSE;MasterCard ElseIf (($left >= 5100) && ($left <=)) if ($cclen 5599) return FALSE;
Australian Bankcard ElseIf ($left = = 5610) if ($cclen!=) return FALSE;
Discover ElseIf ($left = = 6011) if ($cclen!=) return FALSE;
Unknown else return FALSE;
for ($j = 1-($cclen% 2); $j < $cclen; $j + + 2) $chksum + + substr ($number, $j, 1);
for ($j = $cclen% 2; $j < $cclen; $j + 2) {$d = substr ($number, $j, 1) * 2; $chksum + + $d < 10?
$d: $d-9;
if ($chksum%!= 0) return FALSE;
if (mktime (0, 0, 0, substr ($expiry, 0, 2), date ("T"), substr ($expiry, 2, 2)) < time ()) return FALSE;
return TRUE; }?>
I hope this article will help you with your PHP programming.