Php > Authentication
Validation function for LUHNMod10 and variant. Can discriminate credit card
Validation function for LUHNMod10 and variant. Can discriminate credit card numbers of varying lengths. function prestoLUHN($ccn="",$alt="0") { // pre-validations $ccn = ereg_replace("[^[:digit:]]+", "", $ccn); if ((strlen($ccn) < 1)) return FALSE; // Mapping: Double-then-SumOfDigits (0123456789) => (0246813579) for($i=0;$i<=9;$i++) $v[$i] = (($i*2)<9) ? ($i*2):($i*2)-9; // Initial value of $alt (Alternation Pattern) determines which digits are transformed by $v[] during checksum calculation // 0 = apply transform to even-numbered digits from LSD-to-MSD (Conventional LUHNMod10) // 1 = apply transform to odd-numbered digits from LSD-to-MSD (alternative) $checksum = 0; // Calculate checksum from the end of the string (the low-order digit) to beginning of string for($i = strlen($ccn)-1; $i >= 0; $i--) { $digit = substr($ccn, $i, 1); $checksum += $alt ? $v[$digit] : $digit; $alt ^= 1; } // return the checksum descrimination result return !($checksum % 10); }; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage