dingus Posted March 21, 2008 Share Posted March 21, 2008 hey this might be simple then again it might not but how can i validate a credit card number with php? Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/ Share on other sites More sharing options...
cunoodle2 Posted March 21, 2008 Share Posted March 21, 2008 Here you go... //function is used to validate the number on a credit card //$ccnum is the number of the credit card as passed in //$type is the type of the card (Visa, Mastercard, Discover, Amex) function validateCC($ccnum, $type = 'unknown'){ //this code removes dashes and spaces $type = strtolower($type); $ccnum = ereg_replace('[-[:space:]]', '',$ccnum); //Do type specific checks if ($type == 'unknown') { //Skip type specific checks } elseif ($type == 'mastercard'){ if (strlen($ccnum) != 16 || !ereg('^5[1-5]', $ccnum)) return 0; } elseif ($type == 'visa'){ if ((strlen($ccnum) != 13 && strlen($ccnum) != 16) || substr($ccnum, 0, 1) != '4') return 0; } elseif ($type == 'amex'){ if (strlen($ccnum) != 15 || !ereg('^3[47]', $ccnum)) return a; } elseif ($type == 'discover'){ if (strlen($ccnum) != 16 || substr($ccnum, 0, 4) != '6011') return 0; } else { //invalid type entered return -1; } // Start MOD 10 checks $dig = toCharArray($ccnum); $numdig = sizeof ($dig); $j = 0; for ($i=($numdig-2); $i>=0; $i-=2){ $dbl[$j] = $dig[$i] * 2; $j++; } $dblsz = sizeof($dbl); $validate =0; for ($i=0;$i<$dblsz;$i++){ $add = toCharArray($dbl[$i]); for ($j=0;$j<sizeof($add);$j++){ $validate += $add[$j]; } $add = ''; } for ($i=($numdig-1); $i>=0; $i-=2){ $validate += $dig[$i]; } if (substr($validate, -1, 1) == '0') return 1; else return 0; } Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497288 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 hey this might be simple then again it might not but how can i validate a credit card number with php? You don't you let a professional secure payment system such as paypal handle it. Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497290 Share on other sites More sharing options...
rubing Posted March 21, 2008 Share Posted March 21, 2008 You could try the credit card number out at another store to see if it works and then cancel the order before it is fufilled. Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497296 Share on other sites More sharing options...
cmgmyr Posted March 21, 2008 Share Posted March 21, 2008 Hey, check this out real quick: http://bytemycode.com/snippets/snippet/712 I wrote this for one of my projects and maybe it can help you out. Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497311 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 Hey, check this out real quick: http://bytemycode.com/snippets/snippet/712 I wrote this for one of my projects and maybe it can help you out. You are only following the companies prescribed algorithms to designing cards. You have no way of knowing the validness or authenticity of a given card . This is why allowing people who have insurance for fraud and other stuff to handle it makes so much more sense because anyone can follow your algorithm and provide you with "valid CC numbers". The only useful application to taking an user's numbers is if they are making a purchase through you and your online department is just an extension of your brick store so your online processing is done by hand and you manually use your cash register to handle the credit card transaction. Only then would you have security, Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497454 Share on other sites More sharing options...
cmgmyr Posted March 21, 2008 Share Posted March 21, 2008 This was only the first step in the validation process. The second step was validating it through Authorize.net Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497463 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 This was only the first step in the validation process. The second step was validating it through Authorize.net and authroize.net should authorize its consistency anyway because if it ain't consistent it won't match a valid account so your step is sorta pointless still. Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497468 Share on other sites More sharing options...
dingus Posted March 21, 2008 Author Share Posted March 21, 2008 well it was accurately i was writing a mod for a proxy script and i wanted to stop people submitting credit card information over the proxy Quote Link to comment https://forums.phpfreaks.com/topic/97183-validate-cc-number/#findComment-497519 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.