PDA

Click to See Complete Forum and Search --> : Credit card verification


chrisjk
Mar 8th, 2002, 12:39 PM
I need to verify that credit card numbers being entered are "valid" (not that they actually authorise, just fit all checksum requirements) using a PHP script.

Since I have no idea what algorithms are used to check numbers, has anybody seen some code that would do this floating about the web?

I really need it to work for UK debit cards (Switch, Solo, Delta) as well as the usual Mastercard/Visa but any links would be welcome :cool:

Thanks all

scoutt
Mar 8th, 2002, 02:23 PM
did you check www.hotscripts.com

other than that I have not seen any like that. I would think if you want to check it thoroughly you will have to pay some company that can run checks on the #'s you submit. because how else will you check the numbers to see if they are valid, besides if they have all the numbers.

chrisjk
Mar 10th, 2002, 08:06 AM
thanks for the link :D

We have a merchant account with a bank already which we use to actually authorise card numbers, but we want to prevent obviously bogus numbers from even getting that far, like 1111 1111 1111 1111 which is obvisouly not a card would fail, but one that fits the necessary checksums would be submitted for actual authorisation with the bank.

Hopefully that makes sense

Al Smith
Mar 11th, 2002, 03:36 PM
Hi,
I don't know PHP but here's some code for an ASP card number validator I found.
Perhaps you can decipher it enough to create an algorithm for PHP.
Al.



cctest.asp



<html>
<!-- Test Script for credit card information -->
<!-- (c) 1998 by Click Online -->
<!-- http://www.click-online.de -->
<!-- info@click-online.de -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<!-- #include file="checkcc.inc"-->
<title>Click Online Credit Card Test </title>
</head>

<body
<%
response.write "text=""" & textcol1 &_
""" link=""" & textlink &_
""" vlink=""" & textvlink &_
""" alink=""" & textalink &_
""" background=""../images/" &_
bgimgurl & """ bgcolor=""" &_
bgcolor & """" %>>

<p><%number=request("number")
cctype=request("cctype")
if number<>"" then
chk=checkcc(number,cctype)
response.write "<br>Result: "
select case chk
case 0
response.write "Card is ok!"
case 1
response.write "Wrong card type"
case 2
response.write "Wrong length"
case 3
response.write "Wrong length and card type"
case 4
response.write "Wrong checksum"
case 5
response.write "Wrong checksum and card type"
case 6
response.write "Wrong checksum and length"
case 7
response.write "Wrong checksum, length and card type"
case 8
response.write "unknown cardtype"
end select
else
response.write "Please enter a card number"
end if%></p>

<form method="POST">
<p>Card number: <input type="text" name="number" size="20"
value="<%=number%>"></p>
<p>Type: <select name="cctype" size="1">
<option value="V" <%if cctype="V" then response.write "selected"%>>
VISA</option>
<option value="M" <%if cctype="M" then response.write "selected"%>>
Mastercard/Eurocard</option>
<option value="A" <%if cctype="A" then response.write "selected"%>>
American Express</option>
<option value="C" <%if cctype="C" then response.write "selected"%>>
Diners Club / Carte Blanche</option>
<option value="D" <%if cctype="D" then response.write "selected"%>>
Discover</option>
<option value="E" <%if cctype="E" then response.write "selected"%>>
enRoute</option>
<option value="J" <%if cctype="J" then response.write "selected"%>>
JCB</option>
<option value="U" <%if cctype="U" then response.write "selected"%>>
unknown cardtype (test)</option>
</select></p>
<p><input type="submit" value="Test it!" name="B1"></p>
</form>

<p>© 1998 by <a href="http://www.click-online.de">Click Online</a></p>
</body>
</html>



checkcc.inc



<%
' Credit Card check routine for ASP
' (c) 1998 by Click Online
' You may use these functions only if this header is not removed
' http://www.click-online.de
' info@click-online.de


function trimtodigits(tstring)
'removes all chars except of 0-9
s=""
ts=tstring
for x=1 to len(ts)
ch=mid(ts,x,1)
if asc(ch)>=48 and asc(ch)<=57 then
s=s & ch
end if
next
trimtodigits=s
end function

function checkcc(ccnumber,cctype)
'checks credit card number for checksum,length and type
'ccnumber= credit card number (all useless characters are
' being removed before check)
'
'cctype:
' "V" VISA
' "M" Mastercard/Eurocard
' "A" American Express
' "C" Diners Club / Carte Blanche
' "D" Discover
' "E" enRoute
' "J" JCB
'returns: checkcc=0 (Bit0) : card valid
' checkcc=1 (Bit1) : wrong type
' checkcc=2 (Bit2) : wrong length
' checkcc=4 (Bit3) : wrong checksum (MOD10-Test)
' checkcc=8 (Bit4) : cardtype unknown
'
ctype=ucase(cctype)
select case ctype
case "V"
cclength="13;16"
ccprefix="4"
case "M"
cclength="16"
ccprefix="51;52;53;54;55"
case "A"
cclength="15"
ccprefix="34;37"
case "C"
cclength="14"
ccprefix="300;301;302;303;304;305;36;38"
case "D"
cclength="16"
ccprefix="6011"
case "E"
cclength="15"
ccprefix="2014;2149"
case "J"
cclength="15;16"
ccprefix="3;2131;1800"
case else
cclength=""
ccprefix=""
end select
prefixes=split(ccprefix,";",-1)
lengths=split(cclength,";",-1)
number=trimtodigits(ccnumber)
prefixvalid=false
lengthvalid=false
for each prefix in prefixes
if instr(number,prefix)=1 then
prefixvalid=true
end if
next
for each length in lengths
if cstr(len(number))=length then
lengthvalid=true
end if
next
result=0
if not prefixvalid then
result=result+1
end if
if not lengthvalid then
result=result+2
end if
qsum=0
for x=1 to len(number)
ch=mid(number,len(number)-x+1,1)
'response.write ch
if x mod 2=0 then
sum=2*cint(ch)
qsum=qsum+(sum mod 10)
if sum>9 then
qsum=qsum+1
end if
else
qsum=qsum+cint(ch)
end if
next
'response.write qsum
if qsum mod 10<>0 then
result=result+4
end if
if cclength="" then
result=result+8
end if
checkcc=result
end function
%>

chrisjk
Mar 11th, 2002, 05:57 PM
Cool, I should be able to extract some checking info from that, thanks :D

ubunreal69
Mar 19th, 2002, 02:43 AM
i dont think 'Al Smith' believes in a simple, quick, solution :D ;) :)