PHP generates card numbers based on credit card number rules

Source: Internet
Author: User
This article mainly introduces PHP randomly generated credit card number method, involving PHP based on credit card number rules to generate card number of the skills, with a certain reference value, the need for friends can refer to the next

This paper describes the method of randomly generating credit card number in PHP. The specific analysis is as follows:

This PHP code randomly generated credit card number according to the credit card number generation rules, it can be verified, for learning reference only, please do not use for illegal purposes, otherwise the consequences are at your own risk.

<?php/*php Credit card number Generatorcopyright (C) 2006 Graham King graham@darkcoding.netthis program was free Softwar E  You can redistribute it and/ormodify it under the terms of the GNU general public Licenseas published by the Free software Foundation; Either version 2of the License, or (at your option) any later version. Distributed in the hope that it'll be useful,but without any WARRANTY; Without even the implied warranty ofmerchantability or FITNESS for A particular PURPOSE. See THEGNU general public License for more details. You should has received a copy of the GNU general public Licensealong with this program; If not, write to the Free Softwarefoundation, Inc., Wuyi Franklin Street, Fifth Floor, Boston, MA 02110-1301, usa.*/$visaPre Fixlist[] = "4539"; $visaPrefixList [] = "4556"; $visaPrefixList [] = "4916"; $visaPrefixList [] = "4532"; $visaPrefixList [] = "4929"; $visaPrefixList [] = "40240071"; $visaPrefixList [] = "4485"; $visaPrefixList [] = "4716"; $visaPrefixList [] = "4"; $mastercardPrefixList [] = "Wuyi"; $mastercardPrefixList [] = "n"; $mastercardPrefixList [] = "53"; $ mastercardprefixlist[] = "Si"; $mastercardPrefixList [] = "n"; $amexPrefixList [] = "the"; $amexPrefixList [] = "37"; $ Discoverprefixlist[] = "6011"; $dinersPrefixList [] = "n"; $dinersPrefixList [] = "301"; $dinersPrefixList [] = "302"; $ Dinersprefixlist[] = "303"; $dinersPrefixList [] = "n"; $dinersPrefixList [] = "$"; $enRoutePrefixList [] = "2014"; $ Enrouteprefixlist[] = "2149"; $jcbPrefixList [] = "Numbe"; $voyagerPrefixList [] = "8699";/* ' prefix ' is the start of the CC R as a string, any number of digits. ' Length ' was the length of the CC number to generate.  Typically 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 = $pref    ixlist[Array_rand ($prefixList)];  $result [] = Completed_number ($ccnumber, $length); } return $result;}  function output ($title, $numbers) {$result [] = "<p class= ' creditcardnumbers ' >";  $result [] = "

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.