Hi,
suche dringend ein aktuelles script zur validierung von Kreditkarten-nummern. Meins scheint valide Nummern als nicht valide auszuwerfen.
	
Danke der Trallala
							
						
					suche dringend ein aktuelles script zur validierung von Kreditkarten-nummern. Meins scheint valide Nummern als nicht valide auszuwerfen.
PHP-Code:
	
	
<?php
class CCVAL
    {
    var $ccExpM = 0;
    var $ccExpY = 0;
    function _checkSum($ccnum)
        {
        $checksum=0;
        for ($i=(2 - (strlen($ccnum) % 2)); $i <= strlen($ccnum); $i+=2)
            {
            $checksum+=(int)($ccnum{$i - 1});
            }
        // Analyze odd digits in even length strings or even digits in odd length strings.
        for ($i=(strlen($ccnum) % 2) + 1; $i < strlen($ccnum); $i+=2)
            {
            $digit = (int)($ccnum{$i - 1}) * 2;
            if ($digit < 10)
                {
                $checksum+=$digit;
                }
            else
                {
                $checksum+=($digit - 9);
                }
            }
        if (($checksum % 10) == 0)
            return true;
        else
            return false;
        }
    function isVAlidCreditCard($ccnum, $type = "", $returnobj = false)
        {
        /*American Express=1, Diners Club=2, Japan Credit Bureau=3, MasterCard=4, Visacard=5
          passing the Mod 10 algorithm, a credit card number must also pass several different formatting rules
          -> American Express: Must have a prefix of 34 or 37, and must be 15 digits in length
          -> Diners Club: Must have a prefix of 300 to 305, 36, or 38, and must be 14 digits in length
          -> JCB: Must have a prefix of 3, 1800, or 2131, and must be either 15 or 16 digits in length
          -> Mastercard: Must have a prefix of 51 to 55, and must be 16 digits in length
          -> Visa: Must have a prefix of 4, and must be either 13 or 16 digits in length
    
    ^
        */
        $creditcard=array
            (
            "1" => "/^3[47][0-9]{13}$/",
            "2" => "/^3(0[0-5]|[68][0-9])[0-9]{11}$/",
            "3" => "/^(3[0-9]{4}|2131|1800)[0-9]{11}/",
            "4" => "/^5[1-5][0-9]{14}$/",
            "5" => "/^4[0-9]{12}([0-9]{3})?$/"
            );
        if (empty($type))
            {
            $match=false;
            foreach ($creditcard as $type => $pattern)
                if (preg_match($pattern, $ccnum) == 1)
                    {
                    $match=true;
                    break;
                    }
            if (!$match)
                return false;
            else
                {
                if ($returnobj)
                    {
                    $return       =new stdclass;
                    $return->valid=$this->_checkSum($ccnum);
                    $return->ccnum=$ccnum;
                    $return->type =$type;
                    return $return;
                    }
                else
                    return $this->_checkSum($ccnum);
                }
            }
        else
            {
            if (@preg_match($creditcard[strtolower(trim($type))], $ccnum) == 0)
                return false;
            else
                {
                if ($returnobj)
                    {
                    $return       =new stdclass;
                    $return->valid=$this->_checkSum($ccnum);
                    $return->ccnum=$ccnum;
                    $return->type =$type;
                    return $return;
                    }
                else
                    return $this->_checkSum($ccnum);
                }
            }
        }
    function checkExpired($ccExpM, $ccExpY)
        {
        // Get the current year
        $currentYear=date('Y');
        settype($currentYear, 'integer');
        // Get the current year
        $currentMonth=date('m');
        settype($currentMonth, 'integer');
        if (($ccExpY < $currentYear) || ($ccExpM < $currentMonth))
            return FALSE;
        else
            return TRUE;
        }
    }
$cc=new CCVAL;
?>
          
 Moderator
 ENDE MIT OT!
 
Kommentar