PHP   发布时间:2019-11-13  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php实现通用的信用卡验证类大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了php实现通用的信用卡验证类。分享给大家供大家参

原文说明如下:

Credit Card Validation Solution (php Edition) Version 3.5

Description
Credit Card Validation Solution™ uses a four step process to ensure credit card numbers are keyed in correctly. This procedure accurately checks cards from American Express,Australian BankCard,Carte Blache,Diners Club,Discover/Novus,JCB,MasterCard and Visa.
For more information,please read the comments in the code itself.

Installation instructions
SELEct the text between the two lines inDicated,below.
Copy the text.
Open up a text editor.
Paste the text.
Save that file. When saving it,make sure to:
save it in a directory on your webserver,and
name it with an extension that your server will recognize needs parsing by php.
To see it in action,open up that file in your web browswer.

具体代码如下:

php;"> = 3000 and $numberLeft <= 3059) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3600 and $numberLeft <= 3699) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3800 and $numberLeft <= 3889) { $CardName = "Diners Club"; $ShouldLength = 14; } elseif ($NumberLeft >= 3400 and $numberLeft <= 3499) { $CardName = "American Express"; $ShouldLength = 15; } elseif ($NumberLeft >= 3700 and $numberLeft <= 3799) { $CardName = "American Express"; $ShouldLength = 15; } elseif ($NumberLeft >= 3528 and $numberLeft <= 3589) { $CardName = "JCB"; $ShouldLength = 16; } elseif ($NumberLeft >= 3890 and $numberLeft <= 3899) { $CardName = "Carte Blache"; $ShouldLength = 14; } elseif ($NumberLeft >= 4000 and $numberLeft <= 4999) { $CardName = "Visa"; if ($NumberLength > 14) { $ShouldLength = 16; } elseif ($numberLength < 14) { $ShouldLength = 13; } else { echo "
The Visa number entered,$number,in is 14 digits long.
Visa cards usually have 16 digits,though some have 13.
Please check the number and try again.

n"; return falSE; } } elseif ($numberLeft >= 5100 and $numberLeft <= 5599) { $CardName = "MasterCard"; $ShouldLength = 16; } elseif ($numberLeft == 5610) { $CardName = "Australian BankCard"; $ShouldLength = 16; } elseif ($numberLeft == 6011) { $CardName = "Discover/Novus"; $ShouldLength = 16; } else { echo "
The first four digits of the number entered are $numberLeft.
If that's correct,we don't accept that type of credit card.
If it's wrong,please try again.

n"; return falSE; } # 3) Is the number the right length? if ($numberLength <> $ShouldLength) { $Missing = $numberLength - $ShouldLength; if ($Missing < 0) { echo "
The $CardName number entered,is missing " . abs($Missing) . " digit(s).
Please check the number and try again.

n"; } else { echo "
The $CardName number entered,has $Missing too many digit(s).
Please check the number and try again.

n"; } return falSE; } # 4) Does the number pass the Mod 10 Algorithm checksum? if (Mod10Solution($number) == TRUE) { return TRUE; } else { echo "
The $CardName number entered,is invalid.
Please check the number and try again.

n"; return falSE; } } function OnlyNumericSolution ($number) { # Remove any non numeric characters. # Ensure number is no more than 19 characters long. return substr( ereg_replace( "[^0-9]","",$number),19); } function Mod10Solution ($number) { $numberLength = strlen($number); $checksum = 0; # Add even digits in even length Strings # or odd digits in odd length Strings. for ($LOCATIOn = 1 - ($numberLength % 2); $LOCATIOn < $numberLength; $LOCATIOn += 2) { $checksum += substr($number,$LOCATIOn,1); } # Analyze odd digits in even length Strings # or even digits in odd length Strings. for ($LOCATIOn = ($numberLength % 2); $LOCATIOn < $numberLength; $LOCATIOn += 2) { $Digit = substr($number,1) * 2; if ($Digit < 10) { $checksum += $Digit; } else { $checksum += $Digit - 9; } } # Is the checksum divisible by ten? return ($checksum % 10 == 0); } # ----------- BEGIN SAMPLE USER INTERFACE SECTION ------------ # # This section provides a simple sample user interface for the # Credit Card Validation functions. It generates an HTML form # where you enter a card number to check. # # If a number has been posted by the form,check it. if ( isset($number) ) { # Get rid of spaces and non-numeric characters in posted # numbers so they display correctly on the input form. $number = OnlyNumericSolution($number); if (CCValidationSolution($number) == TRUE) { echo "
The $CardName number entered,is valid.
n"; } } else { $number = ""; } # Setup an input form. PosTing it calls this page again. echo "
requEST_URI">n"; echo "
Credit Card number: number" value="$number">n"; echo "check its Validity">n"; echo "

n"; # # ------------ END SAMPLE USER INTERFACE SECTION ------------- ?>

希望本文所述对大家的php程序设计有所帮助。

大佬总结

以上是大佬教程为你收集整理的php实现通用的信用卡验证类全部内容,希望文章能够帮你解决php实现通用的信用卡验证类所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。