I have been using this code for years to check if a credit card is valid prior to sending it off to be processed. Does anyone know if this code is still valid, has it been upgraded, any thoughts at all?
function order_check_card($temp_cc) {
$length=strlen($temp_cc);
if ($length<16) {
return FALSE;
}
$str1="";
$sum2=0;
for ($i=($length-2);$i>=0;$i=$i-2) {
$val1=substr($temp_cc, $i, 1);
$sum1=intval($val1)*2;
$sum1=strval($sum1);
$str1.=$sum1;
$val2=substr($temp_cc, ($i+1), 1);
$sum2+=intval($val2);
$j=$i+1;
}
//Check for odd digit cc nos (AMEX/VISA)
//if so, we add on the '0th' element that is missed from above
$check=$length/2;
if ($check!=floor($check)) {
$val2=substr($temp_cc, 0, 1);
$sum2+=intval($val2);
}
$length2=strlen($str1);
for ($i=($length2-1);$i>=0;$i--) {
$val3=substr($str1, $i, 1);
$sum3+=intval($val3);
}
//Check it is divisible by 10
$card_total=$sum2+$sum3;
$fraction=$card_total/10;
if ($fraction!=floor($fraction)){
return FALSE;
}
return TRUE;
}