[PHP] 验证所有类型的信用卡的php类 →→→→→进入此内容的聊天室

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

回复 "验证所有类型的信用卡的php类"

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

captcha