国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

PHP隨機生成信用卡卡號的方法

2024-05-04 23:33:14
字體:
供稿:網(wǎng)友

這篇文章主要介紹了PHP隨機生成信用卡卡號的方法,涉及php根據(jù)信用卡卡號規(guī)則生成卡號的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了PHP隨機生成信用卡卡號的方法。分享給大家供大家參考。具體分析如下:

這段PHP代碼根據(jù)信用卡卡號產(chǎn)生規(guī)則隨機生成信用卡卡號,是可以通過驗證的,僅供學(xué)習(xí)參考,請不要用于非法用途,否則后果自負(fù)。

 

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

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴文县| 乌兰县| 教育| 高阳县| 聊城市| 肃北| 株洲县| 鸡东县| 洛阳市| 承德县| 罗源县| 清远市| 洛南县| 广南县| 龙山县| 绥芬河市| 安图县| 革吉县| 余姚市| 保德县| 湘阴县| 阿瓦提县| 含山县| 清苑县| 枞阳县| 彭山县| 新平| 平陆县| 瓦房店市| 广东省| 肥城市| 辰溪县| 天镇县| 麻江县| 苍山县| 阳城县| 台州市| 庆云县| 昆山市| 肃南| 曲松县|