Page 1 of 1

Inserting Luhn Algorithm

Posted: Mon Sep 08, 2003 5:16 pm
by Markian
Hi. Forgive the newbie naivte of this question but I'm in deep and am hoping there's a simple answer. Babtism by fire.

Q: Is it a simple copy & paste of the Luhn Algorithminto this .php form processing page below? I want to verify characters in the Credit Card ($cc_no) field. If so, where? I've tried and I suspect it's more complicated. Examples, shoves in the right direction, are much appreciated. Thanks in advance. Markian

/////////////////////////////////////////////////////////

<body>

<?
if (($name=="")||($street_address=="")||($city=="")||($state=="")||($zip=="")||($country=="")||($email=="")||($transport_program=="")||($cc_no=="")||($exp==""))
{
echo "<font face=verdana size=2>Please fill out the application completely before submitting. To return to the Membership Application Page, press the BACK button on your browser.";
}
else
{
$fp=fopen("../results/memapp.txt", "a") ; //w will append or create a new file
flock($fp, LOCK_EX);//lock the file

fwrite($fp,"$name has applied for Membership.\n\n");
fwrite($fp,"CREDENTIALS:\n");
fputs($fp,"MSN:$msn\n");
fputs($fp,"RN:$rn\n");
fputs($fp,"EMT-P:$emtp\n");
fputs($fp,"CFRN:$cfrn\n");
fputs($fp,"CCN:$ccn\n");
fputs($fp,"CEN:$cen\n\n");
fputs($fp,"OTHER CREDENTIALS:$other_credentials\n\n");
fputs($fp,"STREET ADDRESS: $street_address\n");
fputs($fp,"CITY: $city\n");
fputs($fp,"STATE: $state\n");
fputs($fp,"ZIP: $zip\n");
fputs($fp,"COUNTRY: $country\n");
fputs($fp,"HOME PHONE: $home_phone\n");
fputs($fp,"WORK PHONE: $work_phone\n");
fputs($fp,"EMAIL: $email\n");
fputs($fp,"LICENSE NUMBER: $license_number\n");
fputs($fp,"TRANSPORT PROGRAM: $transport_program\n");
fputs($fp,"PAYMENT METHOD: $payment_method\n");
fputs($fp,"CC#: $cc_no\n");
fputs($fp,"EXP: $exp\n");
fputs($fp,"DESIRED MEMBERSHIP LEVEL: $membership_level\n");
fputs($fp,"APPLICANT STATUS: $applicant_status\n\n");
fwrite($fp,"<%>*<$>*<%>*<%>*<$>*<%>*<%>*<$>*<%>*<%>*<$>*<%>*<%>*<$>*<%>\n\n\n");

flock($fp, LOCK_UN); //unlock the file
fclose($fp);

mail ("info@domain.com", "Membership Application Added", wordwrap("$name has applied for Membership.\nTheir e-mail address is: $email. Applicant information has been received.", 72, "\n", 1), "Return-Path:<info@domain.com>\nFrom: Web Site");

mail ("$email", "Thanks for applying for Membership!", wordwrap ("Thank You, $name, for applying for Membership! An representative will be contacting you. This is an auto-reply generated message. Do Not Respond.", 72, "\n", 1), "Return-Path:
<info@domain.com>\nFrom: domain");

echo "<font face=verdana size=2>Thank You, ". $name . ", for applying for Membership! An representative will be contacting you. To return to the website, click your browser BACK button.";
}
?>






</body>
</html>

Posted: Tue Sep 09, 2003 6:38 am
by pootergeist
fputs($fp,"CCN:$ccn\n");
or
fputs($fp,"CC#: $cc_no\n");

I presume that by the time $ccn has got there that you have encrypted it using a private key and some good algorythm (no-one in their right mind would ever store unencrypted credit card numbers in a text file on a server, no matter how secure they believed the server to be) - so using the Lund numeric test would be pointless.

If you are trying to write the credit card number (unencrypted / unmodified) to a text file, I urge you to stop and fix that before going any further.

re:encryption

Posted: Tue Sep 09, 2003 11:38 am
by Markian
Yes, the info is being encrypted through SSL, so I'm OK there. I do appreciate the frankness of your warning though. :)

Still, whenever I place the Luhn Algo. and test it locally, it gives me a slew of error messages stating that I haven't defined variables. What gives? The form script works fine and does all it should before I add this extra bit. I AM placing this code before the other code however, so maybe that's where the problem lies. - Actually now, after re-examining it, of course! Placing the Luhn before everything prevents the variables from being defined! (i think) Thanks again.