PHP Credit Card Number Validator Library
This library can be "included" into any PHP application to check the validity of an entered credit card number.
Used properly, it will tell you type of card entered, and if the number entered is a valid one for that card type
Setup and Usage
- Download the Library and save it as "cccheck.inc.php"
- In your PHP application, "include" it, like this:
<?php include_once("/path/to/cccheck.inc.php"; ?>
- Then, anywhere in your program, you can make calls to the library, as follows:
Call the "validateCC" function with a credit card number.
Returns card type and a 1 on valid card numbers, null on invalid ones.
$ccnumber = $_POST['credit_card_number'];
list($type, $valid) = validateCC($number);
if ( $valid ) {
// Do something fun with the card
echo "Number: <b>$ccnumber</b> ... Type: <b>$type</b> ... Valid: <b>$valid</b>";
}
else {
// Return some sort of error
}
Give it a try here (Don't enter in a real credit card number, though!)
Happy Coding