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 Link to comment https://forums.phpfreaks.com/topic/224261-simple-question/ 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. Link to comment https://forums.phpfreaks.com/topic/224261-simple-question/#findComment-1158679 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 Link to comment https://forums.phpfreaks.com/topic/224261-simple-question/#findComment-1158680 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'] Link to comment https://forums.phpfreaks.com/topic/224261-simple-question/#findComment-1158682 Share on other sites More sharing options...
princeofpersia Posted January 13, 2011 Author Share Posted January 13, 2011 thanks, it worked, love this forum Link to comment https://forums.phpfreaks.com/topic/224261-simple-question/#findComment-1158691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.