欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP隨機(jī)生成信用卡卡號(hào)的方法

 更新時(shí)間:2015年03月23日 15:50:59   作者:heishui  
這篇文章主要介紹了PHP隨機(jī)生成信用卡卡號(hào)的方法,涉及php根據(jù)信用卡卡號(hào)規(guī)則生成卡號(hào)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了PHP隨機(jī)生成信用卡卡號(hào)的方法。分享給大家供大家參考。具體分析如下:

這段PHP代碼根據(jù)信用卡卡號(hào)產(chǎn)生規(guī)則隨機(jī)生成信用卡卡號(hào),是可以通過驗(yàn)證的,僅供學(xué)習(xí)參考,請(qǐng)不要用于非法用途,否則后果自負(fù)。

<?php
/*
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 of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth 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[] = "<div class='creditCardNumbers'>";
  $result[] = "<h3>$title</h3>";
  $result[] = implode('<br />', $numbers);
  $result[]= '</div>';
  return implode('<br />', $result);
}
#
# Main
#
echo "<div class='creditCardSet'>";
$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 "</div>";
echo "<div class='creditCardSet'>";
$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 "</div>";
# Minor cards
echo "<div class='creditCardSet'>";
$discover = credit_card_number($discoverPrefixList, 16, 3);
echo output("Discover", $discover);
$diners = credit_card_number($dinersPrefixList, 14, 3);
echo output("Diners Club", $diners);
echo "</div>";
echo "<div class='creditCardSet'>";
$enRoute = credit_card_number($enRoutePrefixList, 15, 3);
echo output("enRoute", $enRoute);
$jcb = credit_card_number($jcbPrefixList, 16, 3);
echo output("JCB", $jcb);
echo "</div>";
echo "<div class='creditCardSet'>";
$voyager = credit_card_number($voyagerPrefixList, 15, 3);
echo output("Voyager", $voyager);
echo "</div>";
?>

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • php版阿里大于(阿里大魚)短信發(fā)送實(shí)例詳解

    php版阿里大于(阿里大魚)短信發(fā)送實(shí)例詳解

    這篇文章主要介紹了php版阿里大于(阿里大魚)短信發(fā)送實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了阿里大于短信發(fā)送接口的配置與使用技巧,需要的朋友可以參考下
    2016-11-11
  • phplock(php進(jìn)程鎖) v1.0 beta1

    phplock(php進(jìn)程鎖) v1.0 beta1

    PHP在多進(jìn)程模式下(并發(fā)的web訪問)由于沒有內(nèi)置的鎖支持,在處理一些資源的之后,很容易出現(xiàn)并發(fā)性問題。
    2009-11-11
  • php將字符串隨機(jī)分割成不同長(zhǎng)度數(shù)組的方法

    php將字符串隨機(jī)分割成不同長(zhǎng)度數(shù)組的方法

    這篇文章主要介紹了php將字符串隨機(jī)分割成不同長(zhǎng)度數(shù)組的方法,涉及隨機(jī)數(shù)及字符串操作的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • php提示Failed to write session data錯(cuò)誤的解決方法

    php提示Failed to write session data錯(cuò)誤的解決方法

    這篇文章主要介紹了php提示Failed to write session data錯(cuò)誤的解決方法,較為詳細(xì)的分析了session寫入錯(cuò)誤的原因與解決方法,并附帶說明了php的工作機(jī)制,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-12-12
  • PHP文件操作實(shí)現(xiàn)代碼分享

    PHP文件操作實(shí)現(xiàn)代碼分享

    PHP中提供了一系列的I/O函數(shù),能簡(jiǎn)捷地實(shí)現(xiàn)我們所需要的功能,包括文件系統(tǒng)操作和目錄操作(如“復(fù)制[copy]”)。下面給大家介紹的是基本的文件讀寫操作:(1)讀文件;(2)寫文件;(3)追加到文件。
    2011-09-09
  • php反序列化之字符串逃逸詳解

    php反序列化之字符串逃逸詳解

    這篇文章主要為大家詳細(xì)介紹了php反序列化之字符串逃逸,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • php獲取網(wǎng)站百度快照日期的方法

    php獲取網(wǎng)站百度快照日期的方法

    這篇文章主要介紹了php獲取網(wǎng)站百度快照日期的方法,涉及php頁面讀取及正則匹配的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • PHP 加密 Password Hashing API基礎(chǔ)知識(shí)點(diǎn)

    PHP 加密 Password Hashing API基礎(chǔ)知識(shí)點(diǎn)

    在本篇文章里小編給大家分享的是一篇關(guān)于PHP 加密 Password Hashing API基礎(chǔ)知識(shí)點(diǎn),有興趣的朋友們可以學(xué)習(xí)下。
    2020-03-03
  • PHP實(shí)現(xiàn)的簡(jiǎn)單適配器模式示例

    PHP實(shí)現(xiàn)的簡(jiǎn)單適配器模式示例

    這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單適配器模式,結(jié)合具體實(shí)例形式分析了php適配器模式的實(shí)現(xiàn)技巧與調(diào)用方法,需要的朋友可以參考下
    2017-06-06
  • PHP應(yīng)用跨時(shí)區(qū)功能的實(shí)現(xiàn)方法

    PHP應(yīng)用跨時(shí)區(qū)功能的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇關(guān)于PHP應(yīng)用跨時(shí)區(qū)功能的實(shí)現(xiàn)方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03

最新評(píng)論