/* PHP credit card number generator Copyright (C) 2006 Graham King graham@darkcoding.net This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License As published by the Free Software Foundation; either version 2 Of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, But without any warranty; without even the implied warranty MERCHANTABILITY or fitness for a particle PURPOSE. See GNU General Public License for more details. You shoshould have your ed a copy of the GNU General Public License Along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, th Floor, Boston, MA 02110-1301, USA. */ $ VisaPrefixList [] = "4539 "; $ VisaPrefixList [] = "4556 "; $ VisaPrefixList [] = "4916 "; $ VisaPrefixList [] = "4532 "; $ VisaPrefixList [] = "4929 "; $ VisaPrefixList [] = "40240071 "; $ VisaPrefixList [] = "4485 "; $ VisaPrefixList [] = "4716 "; $ VisaPrefixList [] = "4 "; $ MastercardPrefixList [] = "51 "; $ MastercardPrefixList [] = "52 "; $ MastercardPrefixList [] = "53 "; $ MastercardPrefixList [] = "54 "; $ MastercardPrefixList [] = "55 "; $ AmexPrefixList [] = "34 "; $ AmexPrefixList [] = "37 "; $ DiscoverPrefixList [] = "6011 "; $ DinersPrefixList [] = "300 "; $ DinersPrefixList [] = "301 "; $ DinersPrefixList [] = "302 "; $ DinersPrefixList [] = "303 "; $ DinersPrefixList [] = "36 "; $ DinersPrefixList [] = "38 "; $ EnRoutePrefixList [] = "2014 "; $ EnRoutePrefixList [] = "2149 "; $ JcbPrefixList [] = "35 "; $ VoyagerPrefixList [] = "8699 "; /* 'Prefix' is the start of the CC number as a string, any number of digits. 'Length' is the length of the CC number to generate. Typically 13 or 16 */ Function completed_number ($ prefix, $ length ){ $ Ccnumber = $ prefix; # Generate digits While (strlen ($ ccnumber) <($ length-1 )){ $ Ccnumber. = rand (0, 9 ); } # Calculate sum $ Sum = 0; $ Pos = 0; $ ReversedCCnumber = strrev ($ ccnumber ); While ($ pos <$ length-1 ){ $ Odd = $ reversedCCnumber [$ pos] * 2; If ($ odd> 9 ){ $ Odd-= 9; } $ Sum + = $ odd; If ($ pos! = ($ Length-2 )){ $ Sum + = $ reversedCCnumber [$ pos + 1]; } $ Pos + = 2; } # Calculate check digit $ Checkdigit = (floor ($ sum/10) + 1) * 10-$ sum) % 10; $ Ccnumber. = $ checkdigit; Return $ ccnumber; } Function credit_card_number ($ prefixList, $ length, $ howMany ){ For ($ I = 0; $ I <$ howMany; $ I ++ ){ $ Ccnumber = $ prefixList [array_rand ($ prefixList)]; $ Result [] = completed_number ($ ccnumber, $ length ); } Return $ result; } Function output ($ title, $ numbers ){ $ Result [] =" "; $ Result [] = "$ title "; $ Result [] = implode (' ', $ Numbers ); $ Result [] =' '; Return implode (' ', $ Result ); } # # Main # Echo" "; $ Mastercard = credit_card_number ($ mastercardPrefixList, 16, 10 ); Echo output ("Mastercard", $ mastercard ); $ Visa16 = credit_card_number ($ visaPrefixList, 16, 10 ); Echo output ("VISA 16 digit", $ visa16 ); Echo" "; Echo" "; $ Visa13 = credit_card_number ($ visaPrefixList, 13, 5 ); Echo output ("VISA 13 digit", $ visa13 ); $ Amex = credit_card_number ($ amexPrefixList, 15, 5 ); Echo output ("American Express", $ amex ); Echo" "; # Minor cards Echo" "; $ Discover = credit_card_number ($ discoverPrefixList, 16, 3 ); Echo output ("Discover", $ discover ); $ Diners = credit_card_number ($ dinersPrefixList, 14, 3 ); Echo output ("Diners Club", $ diners ); Echo" "; Echo" "; $ EnRoute = credit_card_number ($ enRoutePrefixList, 15, 3 ); Echo output ("enRoute", $ enRoute ); $ Jcb = credit_card_number ($ jcbPrefixList, 16, 3 ); Echo output ("JCB", $ jcb ); Echo" "; Echo" "; $ Voyager = credit_card_number ($ voyagerPrefixList, 15, 3 ); Echo output ("Voyager", $ voyager ); Echo" "; ?> |