[PHP] 随机生成信用卡卡号代码 →→→→→进入此内容的聊天室

来自 , 2020-04-30, 写在 PHP, 查看 104 次.
URL http://www.code666.cn/view/39ae2ed1
  1. <?php
  2. /*
  3. PHP credit card number generator
  4. Copyright (C) 2006 Graham King graham@darkcoding.net
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19. */
  20.  
  21. $visaPrefixList[] =  "4539";
  22. $visaPrefixList[] =  "4556";
  23. $visaPrefixList[] =  "4916";
  24. $visaPrefixList[] =  "4532";
  25. $visaPrefixList[] =  "4929";
  26. $visaPrefixList[] =  "40240071";
  27. $visaPrefixList[] =  "4485";
  28. $visaPrefixList[] =  "4716";
  29. $visaPrefixList[] =  "4";
  30.  
  31. $mastercardPrefixList[] =  "51";
  32. $mastercardPrefixList[] =  "52";
  33. $mastercardPrefixList[] =  "53";
  34. $mastercardPrefixList[] =  "54";
  35. $mastercardPrefixList[] =  "55";
  36.  
  37. $amexPrefixList[] =  "34";
  38. $amexPrefixList[] =  "37";
  39.  
  40. $discoverPrefixList[] = "6011";
  41.  
  42. $dinersPrefixList[] =  "300";
  43. $dinersPrefixList[] =  "301";
  44. $dinersPrefixList[] =  "302";
  45. $dinersPrefixList[] =  "303";
  46. $dinersPrefixList[] =  "36";
  47. $dinersPrefixList[] =  "38";
  48.  
  49. $enRoutePrefixList[] =  "2014";
  50. $enRoutePrefixList[] =  "2149";
  51.  
  52. $jcbPrefixList[] =  "35";
  53.  
  54. $voyagerPrefixList[] = "8699";
  55.  
  56. /*
  57. 'prefix' is the start of the CC number as a string, any number of digits.
  58. 'length' is the length of the CC number to generate. Typically 13 or 16
  59. */
  60. function completed_number($prefix, $length) {
  61.  
  62.     $ccnumber = $prefix;
  63.  
  64.     # generate digits
  65.  
  66.     while ( strlen($ccnumber) < ($length - 1) ) {
  67.         $ccnumber .= rand(0,9);
  68.     }
  69.  
  70.     # Calculate sum
  71.  
  72.     $sum = 0;
  73.     $pos = 0;
  74.  
  75.     $reversedCCnumber = strrev( $ccnumber );
  76.  
  77.     while ( $pos < $length - 1 ) {
  78.  
  79.         $odd = $reversedCCnumber[ $pos ] * 2;
  80.         if ( $odd > 9 ) {
  81.             $odd -= 9;
  82.         }
  83.  
  84.         $sum += $odd;
  85.  
  86.         if ( $pos != ($length - 2) ) {
  87.  
  88.             $sum += $reversedCCnumber[ $pos +1 ];
  89.         }
  90.         $pos += 2;
  91.     }
  92.  
  93.     # Calculate check digit
  94.  
  95.     $checkdigit = (( floor($sum/10) + 1) * 10 - $sum) % 10;
  96.     $ccnumber .= $checkdigit;
  97.  
  98.     return $ccnumber;
  99. }
  100.  
  101. function credit_card_number($prefixList, $length, $howMany) {
  102.  
  103.     for ($i = 0; $i < $howMany; $i++) {
  104.  
  105.         $ccnumber = $prefixList[ array_rand($prefixList) ];
  106.         $result[] = completed_number($ccnumber, $length);
  107.     }
  108.  
  109.     return $result;
  110. }
  111.  
  112. function output($title, $numbers) {
  113.  
  114.     $result[] = "<div class='creditCardNumbers'>";
  115.     $result[] = "<h3>$title</h3>";
  116.     $result[] = implode('<br />', $numbers);
  117.     $result[]= '</div>';
  118.  
  119.     return implode('<br />', $result);
  120. }
  121.  
  122. #
  123. # Main
  124. #
  125.  
  126. echo "<div class='creditCardSet'>";
  127. $mastercard = credit_card_number($mastercardPrefixList, 16, 10);
  128. echo output("Mastercard", $mastercard);
  129.  
  130. $visa16 = credit_card_number($visaPrefixList, 16, 10);
  131. echo output("VISA 16 digit", $visa16);
  132. echo "</div>";
  133.  
  134. echo "<div class='creditCardSet'>";
  135. $visa13 = credit_card_number($visaPrefixList, 13, 5);
  136. echo output("VISA 13 digit", $visa13);
  137.  
  138. $amex = credit_card_number($amexPrefixList, 15, 5);
  139. echo output("American Express", $amex);
  140. echo "</div>";
  141.  
  142. # Minor cards
  143.  
  144. echo "<div class='creditCardSet'>";
  145. $discover = credit_card_number($discoverPrefixList, 16, 3);
  146. echo output("Discover", $discover);
  147.  
  148. $diners = credit_card_number($dinersPrefixList, 14, 3);
  149. echo output("Diners Club", $diners);
  150. echo "</div>";
  151.  
  152. echo "<div class='creditCardSet'>";
  153. $enRoute = credit_card_number($enRoutePrefixList, 15, 3);
  154. echo output("enRoute", $enRoute);
  155.  
  156. $jcb = credit_card_number($jcbPrefixList, 16, 3);
  157. echo output("JCB", $jcb);
  158. echo "</div>";
  159.  
  160. echo "<div class='creditCardSet'>";
  161. $voyager = credit_card_number($voyagerPrefixList, 15, 3);
  162. echo output("Voyager", $voyager);
  163. echo "</div>";
  164. ?>
  165.  
  166.  

回复 "随机生成信用卡卡号代码"

这儿你可以回复上面这条便签

captcha