[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 cc_validation.php

Zen Cart 源代码 cc_validation.php




下载文件

文件名: cc_validation.php
文件类型: PHP文件
文件大小: 4.57 KiB
MD5: 82e93e9f6cf8f90a6ae4145c38bc02b1

cc_validation.php - 关闭高亮
  1. <?php
  2. /**
  3.  * cc_validation Class.
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2010 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version $Id: cc_validation.php 16435 2010-05-28 09:34:32Z drbyte $
  10.  */
  11. if (!defined('IS_ADMIN_FLAG')) {
  12.   die('Illegal Access');
  13. }
  14. /**
  15.  * cc_validation Class.
  16.  * Class to validate credit card numbers etc
  17.  *
  18.  * @package classes
  19.  */
  20. class cc_validation extends base {
  21.   var $cc_type, $cc_number, $cc_expiry_month, $cc_expiry_year;
  22.  
  23.   function validate($number, $expiry_m, $expiry_y, $start_m = null, $start_y = null) {
  24.     $this->cc_number = preg_replace('/[^0-9]/', '', $number);
  25.     // NOTE: We check Solo before Maestro, and Maestro/Switch *before* we check Visa/Mastercard, so we don't have to rule-out numerous types from V/MC matching rules.
  26.     if (preg_match('/^(6334[5-9][0-9]|6767[0-9]{2})[0-9]{10}([0-9]{2,3}?)?$/', $this->cc_number) && CC_ENABLED_SOLO=='1') {
  27.       $this->cc_type = "Solo"; // is also a Maestro product
  28.     } else if (preg_match('/^(49369[8-9]|490303|6333[0-4][0-9]|6759[0-9]{2}|5[0678][0-9]{4}|6[0-9][02-9][02-9][0-9]{2})[0-9]{6,13}?$/', $this->cc_number) && (CC_ENABLED_MAESTRO=='1' || CC_ENABLED_SWITCH=='1')) {
  29.       $this->cc_type = "Maestro";
  30.     } else if (preg_match('/^(49030[2-9]|49033[5-9]|4905[0-9]{2}|49110[1-2]|49117[4-9]|49918[0-2]|4936[0-9]{2}|564182|6333[0-4][0-9])[0-9]{10}([0-9]{2,3}?)?$/', $this->cc_number) && (CC_ENABLED_MAESTRO=='1' || CC_ENABLED_SWITCH=='1')) {
  31.       $this->cc_type = "Maestro"; // SWITCH is now Maestro
  32.     } elseif (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $this->cc_number) && CC_ENABLED_VISA=='1') {
  33.       $this->cc_type = 'Visa';
  34.     } elseif (preg_match('/^5[1-5][0-9]{14}$/', $this->cc_number) && CC_ENABLED_MC=='1') {
  35.       $this->cc_type = 'MasterCard';
  36.     } elseif (preg_match('/^3[47][0-9]{13}$/', $this->cc_number) && CC_ENABLED_AMEX=='1') {
  37.       $this->cc_type = 'American Express';
  38.     } elseif (preg_match('/^3(0[0-5]|[68][0-9])[0-9]{11}$/', $this->cc_number) && CC_ENABLED_DINERS_CLUB=='1') {
  39.       $this->cc_type = 'Diners Club';
  40.     } elseif (preg_match('/^(6011[0-9]{12}|622[1-9][0-9]{12}|64[4-9][0-9]{13}|65[0-9]{14})$/', $this->cc_number) && CC_ENABLED_DISCOVER=='1') {
  41.       $this->cc_type = 'Discover';
  42.     } elseif (preg_match('/^(35(28|29|[3-8][0-9])[0-9]{12}|2131[0-9]{11}|1800[0-9]{11})$/', $this->cc_number) && CC_ENABLED_JCB=='1') {
  43.       $this->cc_type = "JCB";
  44.     } elseif (preg_match('/^5610[0-9]{12}$/', $this->cc_number) && CC_ENABLED_AUSTRALIAN_BANKCARD=='1') {
  45.       $this->cc_type = 'Australian BankCard'; // NOTE: is now obsolete
  46.     } else {
  47.       return -1;
  48.     }
  49.  
  50.     if (is_numeric($expiry_m) && ($expiry_m > 0) && ($expiry_m < 13)) {
  51.       $this->cc_expiry_month = $expiry_m;
  52.     } else {
  53.       return -2;
  54.     }
  55.  
  56.     $current_year = date('Y');
  57.     if (strlen($expiry_y) == 2) $expiry_y = intval(substr($current_year, 0, 2) . $expiry_y);
  58.     if (is_numeric($expiry_y) && ($expiry_y >= $current_year) && ($expiry_y <= ($current_year + 10))) {
  59.       $this->cc_expiry_year = $expiry_y;
  60.     } else {
  61.       return -3;
  62.     }
  63.  
  64.     if ($expiry_y == $current_year) {
  65.       if ($expiry_m < date('n')) {
  66.         return -4;
  67.       }
  68.     }
  69.  
  70.     // check the issue month & year but only for Switch/Solo cards
  71.     if (($start_m || $start_y) && in_array($this->cc_type, array('Switch', 'Solo'))) {
  72.       if (!(is_numeric($start_m) && ($start_m > 0) && ($start_m < 13))) {
  73.         return -2;
  74.       }
  75.  
  76.       if (strlen($start_y) == 2) {
  77.         if ($start_y > 80) {
  78.           $start_y = intval('19' . $start_y);
  79.         } else {
  80.           $start_y = intval('20' . $start_y);
  81.         }
  82.       }
  83.  
  84.       if (!is_numeric($start_y) || ($start_y > $current_year)) {
  85.         return -3;
  86.       }
  87.       if (!($start_y >= ($current_year - 10))) {
  88.         return -3;
  89.       }
  90.     }
  91.     return $this->is_valid();
  92.   }
  93.  
  94.   function is_valid() {
  95.     $cardNumber = strrev($this->cc_number);
  96.     $numSum = 0;
  97.  
  98.     for ($i=0; $i<strlen($cardNumber); $i++) {
  99.       $currentNum = substr($cardNumber, $i, 1);
  100.  
  101.       // Double every second digit
  102.       if ($i % 2 == 1) {
  103.         $currentNum *= 2;
  104.       }
  105.  
  106.       // Add digits of 2-digit numbers together
  107.       if ($currentNum > 9) {
  108.         $firstNum = $currentNum % 10;
  109.         $secondNum = ($currentNum - $firstNum) / 10;
  110.         $currentNum = $firstNum + $secondNum;
  111.       }
  112.  
  113.       $numSum += $currentNum;
  114.     }
  115.  
  116.     // If the total has no remainder it's OK
  117.     return ($numSum % 10 == 0);
  118.   }
  119. }
  120.