Forum Moderators: coopster

Message Too Old, No Replies

Validating credit card numbers

Page comes up blank...what's wrong?

         

ksponline

11:47 pm on Feb 8, 2004 (gmt 0)

10+ Year Member



Hi,

Can someone tell me what I'm doing wrong here? I'm trying to validate the credit card numbers (for example, all Discover cards start with 6011, etc.), but when I submit only a blank page comes up.

I've broken it down to be as small as I can for illustrative purposes.

The form is this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
<title>Account Signup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="720" border="0" align="center" cellpadding="12" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="left" valign="top"><h4>&nbsp;</h4>
<form name="signup" method="post" action="validatecc.php">
<table width="630" border="0" cellspacing="0" cellpadding="2">
<tr>
<td class="right">Credit Card:</td>
<td class="left"><select name="ccType" id="CC_Type">
<option selected>--Please Select</option>
<option value="Visa">Visa</option>
<option value="MC">MasterCard</option>
<option value="Discover">Discover</option>
<option value="Amex">American Express</option>
</select>
</td>
</tr>
<tr>
<td class="right">Credit Card Number:</td>
<td class="left"><input name="ccNumber" type="text" id="ccNumber" size="30">
<span class="small">No Dashes or Spaces</span></td>
</tr>
<tr>
<td width="175" class="right">&nbsp;</td>
<td width="440" class="left">&nbsp;</td>
</tr>
<tr>
<td width="175" class="right">&nbsp;</td>
<td width="440" class="left"><input type="submit" name="Submit" value="Submit">
&nbsp;
<input type="reset" name="Submit2" value="Reset">
</td>
</tr>
<tr>
<td width="175" class="right">&nbsp;</td>
<td width="440" class="left">&nbsp;</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

and this is the page that processes it:


<?php

// credit card validation
// $ccNumber = credit card number;
// $ccType = credit card type: Visa, Discover, MC, Amex;

// Put variable into something we can use

$ccNumber = $_POST['ccNumber'];
$ccType = $_POST['ccType'];
$Visa = $_POST['Visa'];
$Discover = $_POST['Discover'];
$MC = $_POST['MC'];
$Amex = $_POST['Amex'];

function validateCC($ccNumber, $ccType) {

//Make sure there are only digits
$ccNumber = ereg_replace("[-[:space:]]","",$ccNumber);

// Check each credit card type
switch ($ccType) {
case "Visa":
$cardCheck = ereg("^4[0-9]{12}$¦^4[0-9]{15}$",$ccNumber);
break;

case "Discover":
$cardCheck = ereg("^6011[0-9]{12}$",$ccNumber);
break;

case "MC":
$cardCheck = ereg("^5[1-5][0-9]{14}$", $ccNumber);
break;

case "Amex":
$cardCheck = ereg("^3[4¦7][0-9]{13}$",$ccNumber);
break;
}

//Now, check against the Luhn forumula

$cardNumber = strlen($ccNumber);
$total = 0;

for($i = 0; $i < strlen($cardNumber); $i++)
{
$currentNum = substr($cardNumber, $i, 1);
if(floor($currentNum / 2)!= $currentNum / 2)
{
$currentNum *= 2;
}
if(strlen($currentNum) == 2)
{
$firstNum = substr($currentNum, 0, 1);
$secondNum = substr($currentNum, 1, 1);
$currentNum = $firstNum + $secondNum;
}
$numSum += $currentNum;
}

// If the total has no remainder, it's OK

$passCheck = ($numSum % 10 == 0? true : false);

/*If both $validateCC and $passCheck are true, then we return true, indicating that the card number is valid. If not, we return false, indicating that either the card number was in an incorrect format, or it failed the Mod 10 check:*/

if($validateCC && $passCheck)
{
return true;
} else {
return false;
}
}

?>

Thanks in advance for any help...

ksponline

12:35 am on Feb 9, 2004 (gmt 0)

10+ Year Member



Sorry, I've been on this project (not this part) 24/7 for so long I'm more tired than I thought...forgot to call out function.

I'm still having problems, but hopefully I can track that down with the error messages now that it's generating something other than an empty page.