1) { //add the digits together $tmp = 0; //loop through the digits that resulted of //the multiplication by two above and add them //together for ($s = 0; $s < strlen($t); $s++) { $tmp = substr($t, $s, 1) + $tmp; } } else { // result of (* 2) is only one digit long $tmp = $t; } //place the result in an array for later //adding to the odd digits in the credit card number $digit_array [$cnt++] = $tmp; } $tmp = 0; //Add the numbers not doubled earlier ( odd placement ) $l = strlen($card_temp); for ($i = 0; $i < $l; $i = $i + 2) { $tmp = substr($card_temp, $i, 1) + $tmp; } //Add the earlier doubled and digit-added numbers to the result $result = $tmp + array_sum($digit_array); //Check to make sure that the remainder //of dividing by 10 is 0 by using the modulas //operator return ($result % 10 == 0); } /* * validate_credit_card_cvv * The three- or four-digit number on the back of a credit card (on the front for American Express). * @author Valerie Isaksen */ static function validate_credit_card_cvv($creditcard_type, $cvv, $required = true, $creditcard_number='') { if ($required and empty($cvv)) return false; if (empty($creditcard_number)) return true; // for BC reasons $firstnumber = substr($creditcard_number, 0, 1); switch (strtoupper($firstnumber)) { case '3': $cvv_digits = 4; break; default: $cvv_digits = 3; } if (strlen($cvv) == $cvv_digits && strspn($cvv, '0123456789') == $cvv_digits) { return true; } return false; } /** * @param $creditcard_type * @param $month * @param $year * @return bool * @author valerie isaksen */ static function validate_credit_card_date($creditcard_type, $month, $year) { $expires = DateTime::createFromFormat('mY', $month.$year); $now = new DateTime('first day of this month'); if ($expires < $now) { return false; } else { return true; } } } // pure php no closing tag