Jump to content

Simple question


princeofpersia

Recommended Posts

Hi guys, this function below is for card validation, however anycard i enter i get the invalid card number, this is not connected to any gateways, this is just an Luhn card validation demonstration.

 

can you tell me please why i get that?

 

<?php
  if ($_POST['pay'])
    {

	$cardNo = addslashes(strip_tags($_POST['cardNo']));









	function luhnCheck($cardNo) {
    $cardNo = str_replace(" ", "", trim($cardNo));
    if(!is_numeric($cardNo) or strlen($cardNo)>19) return false;
    $skip = $newNum = $total = 0;
    for($i=0;$i<=(strlen($cardNo)-1);$i++) {
        if($skip ==0) {
            $tmpNum = ($cardNo[$i]*2);
            $total += (strlen($tmpNum)==2 ? (substr($tmpNum, 0, 1)+substr($tmpNum, 1)) : $tmpNum);
            $skip = 1;
        }else{
            $total += $cardNo[$i];
            $skip = 0;
        }
    }
    return (($total % 10) == 0);
}

/* Example Usage */
if(luhnCheck($_GET['cc'])) {
    echo("Valid Number.");
}else{
    echo("Invalid Number.");
}





}





?>


<form name="confirm" method="post" action="">

<input type="text" name="cardNo">

                <input type="submit" name="pay" value="Pay Now">
                
  </form>

 

I know it could be a issue with this line if(luhnCheck($_GET['cc'])) { but im wondering where should and how put this cc in my form?

 

regards

 

Link to comment
https://forums.phpfreaks.com/topic/224261-simple-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.