您好,欢迎访问一九零五行业门户网

php根据信用卡卡号规则生成卡号

这篇文章主要介绍了php随机生成信用卡卡号的方法,涉及php根据信用卡卡号规则生成卡号的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了php随机生成信用卡卡号的方法。具体分析如下:
这段php代码根据信用卡卡号产生规则随机生成信用卡卡号,是可以通过验证的,仅供学习参考,请不要用于非法用途,否则后果自负。
<?php/*php credit card number generatorcopyright (c) 2006 graham king graham@darkcoding.netthis program is free software; you can redistribute it and/ormodify it under the terms of the gnu general public licenseas published by the free software foundation; either version 2of the license, or (at your option) any later version.this program is distributed in the hope that it will be useful,but without any warranty; without even the implied warranty ofmerchantability or fitness for a particular purpose. see thegnu general public license for more details.you should have received a copy of the gnu general public licensealong with this program; if not, write to the free softwarefoundation, inc., 51 franklin street, fifth floor, boston, ma 02110-1301, usa.*/$visaprefixlist[] = "4539";$visaprefixlist[] = "4556";$visaprefixlist[] = "4916";$visaprefixlist[] = "4532";$visaprefixlist[] = "4929";$visaprefixlist[] = "40240071";$visaprefixlist[] = "4485";$visaprefixlist[] = "4716";$visaprefixlist[] = "4";$mastercardprefixlist[] = "51";$mastercardprefixlist[] = "52";$mastercardprefixlist[] = "53";$mastercardprefixlist[] = "54";$mastercardprefixlist[] = "55";$amexprefixlist[] = "34";$amexprefixlist[] = "37";$discoverprefixlist[] = "6011";$dinersprefixlist[] = "300";$dinersprefixlist[] = "301";$dinersprefixlist[] = "302";$dinersprefixlist[] = "303";$dinersprefixlist[] = "36";$dinersprefixlist[] = "38";$enrouteprefixlist[] = "2014";$enrouteprefixlist[] = "2149";$jcbprefixlist[] = "35";$voyagerprefixlist[] = "8699";/*'prefix' is the start of the cc number as a string, any number of digits.'length' is the length of the cc number to generate. typically 13 or 16*/function completed_number($prefix, $length) { $ccnumber = $prefix; # generate digits while ( strlen($ccnumber) < ($length - 1) ) { $ccnumber .= rand(0,9); } # calculate sum $sum = 0; $pos = 0; $reversedccnumber = strrev( $ccnumber ); while ( $pos < $length - 1 ) { $odd = $reversedccnumber[ $pos ] * 2; if ( $odd > 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 < $howmany; $i++) { $ccnumber = $prefixlist[ array_rand($prefixlist) ]; $result[] = completed_number($ccnumber, $length); } return $result;}function output($title, $numbers) { $result[] = "<p class='creditcardnumbers'>"; $result[] = "<h3>$title</h3>"; $result[] = implode('<br />', $numbers); $result[]= '</p>'; return implode('<br />', $result);}## main#echo "<p class='creditcardset'>";$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 "</p>";echo "<p class='creditcardset'>";$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 "</p>";# minor cardsecho "<p class='creditcardset'>";$discover = credit_card_number($discoverprefixlist, 16, 3);echo output("discover", $discover);$diners = credit_card_number($dinersprefixlist, 14, 3);echo output("diners club", $diners);echo "</p>";echo "<p class='creditcardset'>";$enroute = credit_card_number($enrouteprefixlist, 15, 3);echo output("enroute", $enroute);$jcb = credit_card_number($jcbprefixlist, 16, 3);echo output("jcb", $jcb);echo "</p>";echo "<p class='creditcardset'>";$voyager = credit_card_number($voyagerprefixlist, 15, 3);echo output("voyager", $voyager);echo "</p>";?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php分析与操作字符串以及标签云的生成
php将任意进制数转换成10进制的方法
php将两个数组进行相减的方法
以上就是php根据信用卡卡号规则生成卡号的详细内容。
其它类似信息

推荐信息