Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcctool.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezcctool.php 6200 2001-07-19 11:33:57Z jakobn $
5 //
6 // Definition of eZCCTool class
7 //
8 // Created on: <07-Feb-2001 10:59:41 ce>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
30
33 class eZCCTool
34 {
35 public static function checkCC( $CCNumber,$month,$year )
36 {
37 $ret = false;
38
39 if ( $CCNumber != false )
40 {
41 // Set the current date
42 $date = time();
43 $currentYear = date( "Y", $date );
44 $currentMonth = date( "m", $date );
45
46 if ( $month < $currentMonth && $year == $currentYear )
47 {
48 return false;
49 }
50 else
51 {
52 $ret = true;
53 }
54
55 $CCNumberLength = strlen ( $CCNumber );
56
57 if ( $CCNumberLength != 13 && $CCNumberLength != 15 && $CCNumberLength != 16 )
58 {
59 return false;
60 }
61 else
62 {
63 $ret = true;
64 }
65
66
67 if ( ( $CCNumberLength % 2 ) == 0 )
68 {
69 $pair = 0;
70 }
71 else
72 {
73 $pair = 2;
74 }
75
76 // Get each number of the card and put it in an array
77 for ( $i=0; $i != $CCNumberLength; $i++ )
78 {
79 $numberArray[$i] = substr( $CCNumber, $i, 1 );
80 }
81
82 // Algorithm Mod10 modificated (by me :-)
83 for ( $nume = ($p/2); $nume != $CCNumberLength-$pair; $nume = $nume + 2)
84 {
85 $numberArray[$nume] = $numberArray[$nume] * 2;
86 if ( $numberArray[$nume] >= 10 )
87 {
88 $X1 = substr( $numberArray[$nume],0,1 );
89 $X2 = substr( $numberArray[$nume],1,1 );
90 $numberArray[$nume] = substr( $numberArray[$nume],0,1 ) + substr( $numberArray[$nume],1,1 );
91 }
92 }
93
94 // Sums each value of the modificated array
95 // Check the result of the algorithm
96 for( $i=0; $i != $CCNumberLength; $i++ )
97 {
98 $val = $val + $numberArray[$i];
99 }
100
101 // Please note: if the second number of the result of algorithm is not 0
102 // then the card is NOT valid
103 if ( $val == 0 )
104 {
105 return false;
106 }
107
108 if ( substr( $val,1,1 ) != 0)
109 {
110 return false;
111 }
112 else
113 {
114 return true;
115 }
116 }
117 }
118 }
119
120 ?>
$i
$i
Definition: admin/adlist.php:91
$year
else $year
Definition: appointmentedit.php:655
$month
else $month
Definition: appointmentedit.php:660
$date
$date
Definition: bugpreview.php:66
eZCCTool
Provide utility functions for CreditCards.
Definition: ezcctool.php:34
eZCCTool\checkCC
static checkCC( $CCNumber, $month, $year)
Definition: ezcctool.php:35
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.