Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merged from HEAD

  • Loading branch information...
commit 2efe76b0b396f93ecfa131f00877d4b98f20e3d6 1 parent a5a520f
authored March 21, 2006

Showing 1 changed file with 101 additions and 103 deletions. Show diff stats Hide diff stats

  1. 204  enrol/authorize/ccval.php
204  enrol/authorize/ccval.php
... ...
@@ -1,128 +1,126 @@
1 1
 <?php // $Id$
2 2
 /************************************************************************
3  
- *
4  
- * CCVal - Credit Card Validation function.
5  
- *
6  
- * Copyright (c) 1999, 2003 Holotech Enterprises. All rights reserved.
7  
- * You may freely modify and use this function for your own purposes. You
8  
- * may freely distribute it, without modification and with this notice
9  
- * and entire header intact.
10  
- *
11  
- * This function accepts a credit card number and, optionally, a code for
12  
- * a credit card name. If a Name code is specified, the number is checked
13  
- * against card-specific criteria, then validated with the Luhn Mod 10
14  
- * formula. Otherwise it is only checked against the formula. Valid name
15  
- * codes are:
16  
- *
17  
- *    mcd - Master Card
18  
- *    vis - Visa
19  
- *    amx - American Express
20  
- *    dsc - Discover
21  
- *    dnc - Diners Club
22  
- *    jcb - JCB
23  
- *    swi - Switch
24  
- *    dlt - Delta
25  
- *    enr - EnRoute
26  
- *
27  
- * You can also optionally specify an expiration date in the formay mmyy.
28  
- * If the validation fails on the date, the function returns 0. If it
29  
- * fails on the number validation, it returns false.
30  
- *
31  
- * A description of the criteria used in this function can be found at
32  
- * http://www.paylib.net/ccval.html. If you have any questions or
33  
- * comments, please direct them to ccval@holotech.net
34  
- *
35  
- *                                          Alan Little
36  
- *                                          Holotech Enterprises
37  
- *                                          http://www.holotech.net/
38  
- *                                          August 2003
39  
- *
40  
- ************************************************************************/
41  
-
42  
-  function CCVal($Num, $Name = "n/a", $Exp = "") {
43  
-
44  
-//  Check the expiration date first
45  
-    if (strlen($Exp)) {
46  
-      $Month = substr($Exp, 0, 2);
47  
-      $Year  = substr($Exp, -2);
48  
-
49  
-      $WorkDate = "$Month/01/$Year";
50  
-      $WorkDate = strtotime($WorkDate);
51  
-      $LastDay  = date("t", $WorkDate);
52  
-
53  
-      $Expires  = strtotime("$Month/$LastDay/$Year 11:59:59");
54  
-      if ($Expires < time()) return 0;
  3
+*
  4
+* CCVal - Credit Card Validation function.
  5
+*
  6
+* Copyright (c) 1999, 2003 Holotech Enterprises. All rights reserved.
  7
+* You may freely modify and use this function for your own purposes. You
  8
+* may freely distribute it, without modification and with this notice
  9
+* and entire header intact.
  10
+*
  11
+* This function accepts a credit card number and, optionally, a code for
  12
+* a credit card name. If a Name code is specified, the number is checked
  13
+* against card-specific criteria, then validated with the Luhn Mod 10
  14
+* formula. Otherwise it is only checked against the formula. Valid name
  15
+* codes are:
  16
+*
  17
+*    mcd - Master Card
  18
+*    vis - Visa
  19
+*    amx - American Express
  20
+*    dsc - Discover
  21
+*    dnc - Diners Club
  22
+*    jcb - JCB
  23
+*    swi - Switch
  24
+*    dlt - Delta
  25
+*    enr - EnRoute
  26
+*
  27
+* You can also optionally specify an expiration date in the formay mmyy.
  28
+* If the validation fails on the date, the function returns 0. If it
  29
+* fails on the number validation, it returns false.
  30
+*
  31
+* A description of the criteria used in this function can be found at
  32
+* http://www.paylib.net/ccval.html. If you have any questions or
  33
+* comments, please direct them to ccval@holotech.net
  34
+*
  35
+*                                          Alan Little
  36
+*                                          Holotech Enterprises
  37
+*                                          http://www.holotech.net/
  38
+*                                          August 2003
  39
+*
  40
+************************************************************************/
  41
+
  42
+function CCVal($Num, $Name = "n/a", $Exp = "")
  43
+{
  44
+    // Check the expiration date first
  45
+    if (strlen($Exp))
  46
+    {
  47
+        $Month = substr($Exp, 0, 2);
  48
+        $Year  = substr($Exp, -2);
  49
+        $WorkDate = "$Month/01/$Year";
  50
+        $WorkDate = strtotime($WorkDate);
  51
+        $LastDay  = date("t", $WorkDate);
  52
+        $Expires  = strtotime("$Month/$LastDay/$Year 11:59:59");
  53
+        if ($Expires < time()) return 0;
55 54
     }
56 55
 
57  
-//  Innocent until proven guilty
  56
+    //  Innocent until proven guilty
58 57
     $GoodCard = true;
59 58
 
60  
-//  Get rid of any non-digits
  59
+    //  Get rid of any non-digits
61 60
     $Num = ereg_replace("[^0-9]", "", $Num);
62 61
 
63  
-//  Perform card-specific checks, if applicable
64  
-    switch ($Name) {
  62
+    // Perform card-specific checks, if applicable
  63
+    switch ($Name)
  64
+    {
  65
+        case "mcd" :
  66
+        $GoodCard = ereg("^5[1-5].{14}$", $Num);
  67
+        break;
65 68
 
66  
-    case "mcd" :
67  
-      $GoodCard = ereg("^5[1-5].{14}$", $Num);
68  
-      break;
  69
+        case "vis" :
  70
+        $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
  71
+        break;
69 72
 
70  
-    case "vis" :
71  
-      $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
72  
-      break;
  73
+        case "amx" :
  74
+        $GoodCard = ereg("^3[47].{13}$", $Num);
  75
+        break;
73 76
 
74  
-    case "amx" :
75  
-      $GoodCard = ereg("^3[47].{13}$", $Num);
76  
-      break;
  77
+        case "dsc" :
  78
+        $GoodCard = ereg("^6011.{12}$", $Num);
  79
+        break;
77 80
 
78  
-    case "dsc" :
79  
-      $GoodCard = ereg("^6011.{12}$", $Num);
80  
-      break;
  81
+        case "dnc" :
  82
+        $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
  83
+        break;
81 84
 
82  
-    case "dnc" :
83  
-      $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
84  
-      break;
  85
+        case "jcb" :
  86
+        $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
  87
+        break;
85 88
 
86  
-    case "jcb" :
87  
-      $GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
88  
-      break;
89  
-  
90  
-    case "dlt" :
91  
-      $GoodCard = ereg("^4.{15}$", $Num);
92  
-      break;
  89
+        case "dlt" :
  90
+        $GoodCard = ereg("^4.{15}$", $Num);
  91
+        break;
93 92
 
94  
-    case "swi" :
95  
-      $GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
96  
-      break;
  93
+        case "swi" :
  94
+        $GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
  95
+        break;
97 96
 
98  
-    case "enr" :
99  
-      $GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
100  
-      break;
  97
+        case "enr" :
  98
+        $GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
  99
+        break;
101 100
     }
102 101
 
103  
-//  The Luhn formula works right to left, so reverse the number.
  102
+    // The Luhn formula works right to left, so reverse the number.
104 103
     $Num = strrev($Num);
105  
-
106 104
     $Total = 0;
107 105
 
108  
-    for ($x=0; $x<strlen($Num); $x++) {
109  
-      $digit = substr($Num,$x,1);
110  
-
111  
-//    If it's an odd digit, double it
112  
-      if ($x/2 != floor($x/2)) {
113  
-        $digit *= 2;
  106
+    for ($x=0; $x < strlen($Num); $x++)
  107
+    {
  108
+        $digit = substr($Num, $x, 1);
114 109
 
115  
-//    If the result is two digits, add them
116  
-        if (strlen($digit) == 2)
117  
-          $digit = substr($digit,0,1) + substr($digit,1,1);
118  
-      }
  110
+        // If it's an odd digit, double it
  111
+        if ($x/2 != floor($x/2)) {
  112
+            $digit *= 2;
119 113
 
120  
-//    Add the current digit, doubled and added if applicable, to the Total
121  
-      $Total += $digit;
  114
+            // If the result is two digits, add them
  115
+            if (strlen($digit) == 2)
  116
+                $digit = substr($digit, 0, 1) + substr($digit, 1, 1);
  117
+        }
  118
+        // Add the current digit, doubled and added if applicable, to the Total
  119
+        $Total += $digit;
122 120
     }
123 121
 
124  
-//  If it passed (or bypassed) the card-specific check and the Total is
125  
-//  evenly divisible by 10, it's cool!
126  
-    if ($GoodCard && $Total % 10 == 0) return true; else return false;
127  
-  }
128  
-?>
  122
+    // If it passed (or bypassed) the card-specific check and the Total is
  123
+    // evenly divisible by 10, it's cool!
  124
+    return ($GoodCard && $Total % 10 == 0);
  125
+}
  126
+?>

0 notes on commit 2efe76b

Please sign in to comment.
Something went wrong with that request. Please try again.