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

首頁(yè) > 開(kāi)發(fā) > PHP > 正文

php實(shí)現(xiàn)用于驗(yàn)證所有類型的信用卡類

2024-05-04 23:33:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了php實(shí)現(xiàn)用于驗(yàn)證所有類型的信用卡類,實(shí)例分析了信用卡類的實(shí)現(xiàn)原理與相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)用于驗(yàn)證所有類型的信用卡類。分享給大家供大家參考。具體如下:

這個(gè)php類比較完整,可以用于驗(yàn)證各種不同的信用卡,針對(duì)信用卡的卡號(hào)的通用規(guī)則進(jìn)行了驗(yàn)證,同時(shí)對(duì)不同類型的信用卡進(jìn)行了針對(duì)性的識(shí)別。

代碼接受一個(gè)信用卡號(hào)碼和有效日期,如果兩者都有效,則返回TRUE,否則返回FALSE。

本插件接受以下參數(shù):

$number 表示信用卡號(hào)碼的一個(gè)字符串

$expiry 信用卡有效日期,采用07/12或0712這樣的格式

 

 
  1. <?php 
  2. // Plug-in 32: Validate Credit Card 
  3. // This is an executable example with additional code supplied 
  4. // To obtain just the plug-ins please click on the Download link 
  5. $card = "4567 1234 5678 9101"
  6. $exp = "06/11"
  7. echo "Validating: $card : $exp<br>"
  8. $result = PIPHP_ValidateCC($card$exp); 
  9. if ($result != FALSE) echo "Card Validated"
  10. else echo "Card did not validate"
  11. function PIPHP_ValidateCC($number$expiry
  12. // Plug-in 32: Validate Credit Card 
  13. // 
  14. // This plug-in accepts a credit card number and 
  15. // an expiry date and returns TRUE or FALSE, 
  16. // depending on whether the details pass date 
  17. // and checksum validation. The arguments required 
  18. // are: 
  19. // 
  20. // $number: Credit Card Number 
  21. // $expiry: Expiry date in the form: 
  22. // 07/12 or 0712 (for July, 2012) 
  23. $number = preg_replace('/[^/d]/'''$number); 
  24. $expiry = preg_replace('/[^/d]/'''$expiry); 
  25. $left = substr($number, 0, 4); 
  26. $cclen = strlen($number); 
  27. $chksum = 0; 
  28. // Diners Club 
  29. if (($left >= 3000) && ($left <= 3059) || 
  30. ($left >= 3600) && ($left <= 3699) || 
  31. ($left >= 3800) && ($left <= 3889)) 
  32. if ($cclen != 14) return FALSE; 
  33. // JCB 
  34. if (($left >= 3088) && ($left <= 3094) || 
  35. ($left >= 3096) && ($left <= 3102) || 
  36. ($left >= 3112) && ($left <= 3120) || 
  37. ($left >= 3158) && ($left <= 3159) || 
  38. ($left >= 3337) && ($left <= 3349) || 
  39. ($left >= 3528) && ($left <= 3589)) 
  40. if ($cclen != 16) return FALSE; 
  41. // American Express 
  42. elseif (($left >= 3400) && ($left <= 3499) || 
  43. ($left >= 3700) && ($left <= 3799)) 
  44. if ($cclen != 15) return FALSE; 
  45. // Carte Blanche 
  46. elseif (($left >= 3890) && ($left <= 3899)) 
  47. if ($cclen != 14) return FALSE; 
  48. // Visa 
  49. elseif (($left >= 4000) && ($left <= 4999)) 
  50. if ($cclen != 13 && $cclen != 16) return FALSE; 
  51. // MasterCard 
  52. elseif (($left >= 5100) && ($left <= 5599)) 
  53. if ($cclen != 16) return FALSE; 
  54. // Australian BankCard 
  55. elseif ($left == 5610) 
  56. if ($cclen != 16) return FALSE; 
  57. // Discover 
  58. elseif ($left == 6011) 
  59. if ($cclen != 16) return FALSE; 
  60. // Unknown 
  61. else return FALSE; 
  62. for ($j = 1 - ($cclen % 2); $j < $cclen$j += 2) 
  63. $chksum += substr($number$j, 1); 
  64. for ($j = $cclen % 2; $j < $cclen$j += 2) 
  65. $d = substr($number$j, 1) * 2; 
  66. $chksum += $d < 10 ? $d : $d - 9; 
  67. if ($chksum % 10 != 0) return FALSE; 
  68. if (mktime(0, 0, 0, substr($expiry, 0, 2), date("t"), 
  69. substr($expiry, 2, 2)) < time()) return FALSE; 
  70. return TRUE; 
  71. ?> 

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

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 雷山县| 海晏县| 南平市| 仁布县| 呼伦贝尔市| 石屏县| 大埔区| 华坪县| 福州市| 景宁| 福州市| 获嘉县| 云林县| 寿光市| 邹平县| 茌平县| 稷山县| 徐州市| 徐水县| 临西县| 城步| 张家港市| 桓台县| 秦皇岛市| 洛隆县| 青浦区| 罗田县| 沾益县| 辛集市| 北安市| 临清市| 乌鲁木齐县| 望谟县| 重庆市| 旬阳县| 玉林市| 瑞昌市| 富源县| 吕梁市| 铜梁县| 赤壁市|