PHP随机生成信用卡卡号的方法_php技巧
程序员文章站
2022-05-24 14:06:36
...
本文实例讲述了PHP随机生成信用卡卡号的方法。分享给大家供大家参考。具体分析如下:
';
return implode('
', $result); } # # Main # echo "
这段PHP代码根据信用卡卡号产生规则随机生成信用卡卡号,是可以通过验证的,仅供学习参考,请不要用于非法用途,否则后果自负。
9 ) { $odd -= 9; } $sum += $odd; if ( $pos != ($length - 2) ) { $sum += $reversedCCnumber[ $pos +1 ]; } $pos += 2; } # Calculate check digit $checkdigit = (( floor($sum/10) + 1) * 10 - $sum) % 10; $ccnumber .= $checkdigit; return $ccnumber; } function credit_card_number($prefixList, $length, $howMany) { for ($i = 0; $i "; $result[] = "$title
"; $result[] = implode('
', $numbers); $result[]= '
', $result); } # # Main # echo "
";
$mastercard = credit_card_number($mastercardPrefixList, 16, 10);
echo output("Mastercard", $mastercard);
$visa16 = credit_card_number($visaPrefixList, 16, 10);
echo output("VISA 16 digit", $visa16);
echo "
";
echo "";
$visa13 = credit_card_number($visaPrefixList, 13, 5);
echo output("VISA 13 digit", $visa13);
$amex = credit_card_number($amexPrefixList, 15, 5);
echo output("American Express", $amex);
echo "
";
# Minor cards
echo "";
$discover = credit_card_number($discoverPrefixList, 16, 3);
echo output("Discover", $discover);
$diners = credit_card_number($dinersPrefixList, 14, 3);
echo output("Diners Club", $diners);
echo "
";
echo "";
$enRoute = credit_card_number($enRoutePrefixList, 15, 3);
echo output("enRoute", $enRoute);
$jcb = credit_card_number($jcbPrefixList, 16, 3);
echo output("JCB", $jcb);
echo "
";
echo "";
$voyager = credit_card_number($voyagerPrefixList, 15, 3);
echo output("Voyager", $voyager);
echo "
";
?>