note 11400 added to Mathematical Functions
| From: | ian at mp3 dot com | Date: | Mon, 19 Feb 2001 20:43:02 +0000 |
| Subject: | note 11400 added to Mathematical Functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11254@lists.php.net to get a copy of this message | ||
for those looking for a credit card verification function i wrote a simple LUHN Formula algorithm:
$valid = 1;
$numOfDigits = 0 - strlen($ccNumber);
$i = -1;
while ($i>=$numOfDigits){
if (($i % 2) == 0){
$double = 2*(substr($ccNumber, $i, 1));
$total += substr($double,0,1);
if (strlen($double > 1)){
$total += substr($double,1,1);
}
} else {
$total += substr($ccNumber, $i, 1);
}
$i--;
}
if (($total % 10) != 0){
$valid = 0;
}
http://www.php.net/manual/en/ref.math.php