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

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 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
希望本文所述对大家的php程序设计有所帮助。
其它类似信息

推荐信息