PHP implementation is used to verify all types of credit card classes, all types of credit card _php tutorials

Source: Internet
Author: User

PHP implementations are used to verify all types of credit card classes, all types of credit cards


This example describes the PHP implementation used to validate all types of credit card classes. Share to everyone for your reference. Specific as follows:

This PHP class is more complete, can be used to verify a variety of credit cards, the card number of the common rules for credit card verification, while the different types of credit cards targeted identification.
The code accepts a credit card number and a valid date, and returns True if both are valid, otherwise false.

This plugin accepts the following parameters:
$number A string representing the credit card number
$expiry credit card expiration date in 07/12 or 0712 format

<?php//Plug-in 32:validate credits card//This is a executable example with additional code supplied//to obtain just The Plug-ins click on the Download link$card = "4567 1234 5678 9101"; $exp = "06/11"; echo "Validating: $card: $e Xp
"; $result = PIPHP_VALIDATECC ($card, $exp); if ($result! = FALSE) echo" card Validated "; else echo" card did not validate "; Fu Nction PIPHP_VALIDATECC ($number, $expiry) {//plug-in 32:validate credit card///The plug-in accepts a credit card Number and//an expiry date and returns TRUE or FALSE,//depending on whether the details pass date//and checksum Validation. The arguments required//IS:////$number: Credit Card number//$expiry: expiry date in the form://07/12 O R 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 >=) && ($left <= 3059) | | ($left >= 3600) && ($left <= 3699) | | ($left >= 3800) && ($left <= 3889)) if ($cclen! =) return FALSE; JCB if (($left >= 3088) && ($left <= 3094) | | ($left >= 3096) &Amp;& ($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)) if ($cclen! =) return FALSE; Carte Blanche ElseIf (($left >= 3890) && ($left <= 3899)) if ($cclen! =) return FALSE; Visa ElseIf (($left >= 4000) && ($left <= 4999)) if ($cclen! = && $cclen! =) return Fals E MasterCard ElseIf (($left >= 5100) && ($left <= 5599)) if ($cclen! =) 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 is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/972642.html www.bkjia.com true http://www.bkjia.com/PHPjc/972642.html techarticle the PHP implementation is used to validate all types of credit card classes, all types of credit cards This example describes the PHP implementation used to validate all types of credit card classes. Share to everyone for your reference. Specific ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.