princeofpersia Posted January 13, 2011 Share Posted January 13, 2011 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 Your form doesn't use GET, it uses POST. Quote Link to comment Share on other sites More sharing options...
rondog Posted January 13, 2011 Share Posted January 13, 2011 since you are using $_GET['cc'], you should have that key pair in your URL bar. http://site.com/?cc=3452345234 Quote Link to comment Share on other sites More sharing options...
rondog Posted January 13, 2011 Share Posted January 13, 2011 also make a new text field called cc and change the $_GET['cc'] to $_POST['cc'] Quote Link to comment Share on other sites More sharing options...
princeofpersia Posted January 13, 2011 Author Share Posted January 13, 2011 thanks, it worked, love this forum Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.