WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A set of functions to check the validity of a credit card number.
Categories : Ecommerce, Credit Cards, PHP Update Picture
Brett Error
Date : Jan 17th 1999
Grade : 3 of 5 (graded 8 times)
Viewed : 19102
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Brett Error
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

A set of functions to check the validity of a credit card number. ccValidate
($number, $type) returns 1 if the account number is valid, zero if not. The
$type argument is optional. If included, it will perform additional checking to
ensure the card is of the type specified. Valid types include: visa,
mastercard, discover, and amex.

<?php

////////////////////////////////////////////////////
//
//
// Credit card validation routine //
// May 15,
1998 //
// By Brett
Error //
// [email protected] //
//
//
// validateCC($number[,$type]) //
// Uses the MOD 10 algorythm to determine if a //
// credit card number is valid. //
//
//
// $number = credit card account number //
// $type is optional. Setting type to //
// visa, mastercard, discover, or amex will //
// perform additional checking on the account //
//
number.
//
//
//
// The function returns 1 (true) if the CC is //
// valid, 0 (false) if it is invalid, and -1 if //
// the type entered does not match the supported //
// types listed
above. //
//
//
////////////////////////////////////////////////////


function validateCC($ccnum, $type = 'unknown'){


//Clean up input

$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;
}


// takes a string and returns an array of characters

function toCharArray($input){
$len = strlen($input);
for ($j=0;$j<$len;$j++){
$char[$j] = substr($input, $j, 1);
}
return ($char);
}

?>



an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
After discovering some credit card validation routines didnt work - here is one that I found works with all the numbers I have tried so far
Categories : Credit Cards, Ecommerce, PHP
ECHOcart - Open Source Shopping Cart
Categories : PHP, Credit Cards, Ecommerce
credit card security code
Categories : PHP, Credit Cards, PHP Classes, Credit Cards
Credit Card validation routine. Uses MOD 10 to check if credit card number is valid.
Categories : Ecommerce, Credit Cards, PHP, Complete Programs
Validation function for LUHNMod10 and variant. Can discriminate credit card numbers of varying lengths. Uses [Double >> Sum-of-Digits] transform.
Categories : Credit Cards, Authentication, Ecommerce, PHP
How to validate an Israeli ID number.
Categories : Ecommerce, PHP, Algorithms
Real-Time Transaction Processing PHP Class. Credit Cards & Checks. Supports system check, address verification, authorization and deposit, deposit, credit, commercial card, electronic check debit, and more.
Categories : PHP Classes, OpenSSL, Credit Cards, Ecommerce, Verisign Payflow Pro
open source online php shop project ecommerce commerce
Categories : PHP, Ecommerce
shopping cart class with add/edit/delete product functionality.
Categories : PHP, PHP Classes, Ecommerce
Shopping Basket On-Line Ordering System.
Categories : Complete Programs, MySQL, PHP, Ecommerce, Databases
Example Shopping cart class
Categories : Ecommerce, PHP, PHP Classes
Credit Card Numbers for testing
Categories : Credit Cards, Ecommerce, Debugging
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel