Home >Backend Development >PHP Tutorial >Write PHP to batch generate unique card number password codes_PHP tutorial

Write PHP to batch generate unique card number password codes_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:53:541008browse

Write php to batch generate unique card number and password codes

What this article shares with you is a very practical code that is often used in projects and can generate unique card numbers in batches There are two methods for card number passwords. Friends in need can refer to them.

When I was free, I wanted to improve my skills in array manipulation in PHP, so I wrote the following small code, which can randomly generate arrays corresponding to card numbers and passwords, and automatically remove repetitions. There is no idea, just pure in vain.

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

function MakeCard()

{

set_time_limit(0);

//处理缓冲区

ob_end_clean();

ob_implicit_flush(true);

echo str_pad(" ", 256);

if(intval($_POST['num']>0)) $num=intval($_POST['num']); //数量

if(intval($_POST['point']>0)) $point=intval($_POST['point']); //点数

if(intval($_POST['batch']>0)) $batch=intval($_POST['batch']); //批号

if(($_POST['ym']!="")) $ym=$_POST['ym']; //发行年月

else $ym=date('ym');

 

if($num==0) return;

 

$num=$num*100; //卡的张数,即记录数

 

echo "

开始 ".date("H:i:s")." ";

 

for($i=1;$i<=$num;$i )

{

$sn=sprintf("s%ss",$batch,$ym,$i);

$seek=mt_rand(0,9999).mt_rand(0,9999).mt_rand(0,9999); //12位

$start=mt_rand(0,20);

$str=strtoupper(substr(md5($seek),$start,12));

$str=str_replace("O",chr(mt_rand(65,78)),$str);

$str=str_replace("0",chr(mt_rand(65,78)),$str);

$row=array('sn'=>$sn,'password'=>$str,'created'=>time(),'point'=>$point);

//查重

//在这里加插入数据的代码.

print_r($row);

}

echo " 结束 ".date("H:i:s")."";

printf("
成功生成:%s万个 %s点 的密码

",$num/1e4,$point);

return $num;

} //函数结束

 

$_POST['num']=1;

$_POST['point']=10;

$_POST['batch']=10;

$_POST['ym']='1405';

echo MakeCard(); ?>

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<🎜>function MakeCard()<🎜> <🎜>{<🎜> <🎜>set_time_limit(0);<🎜> <🎜> <🎜> <🎜>//Processing buffer<🎜> <🎜>ob_end_clean();<🎜> <🎜>ob_implicit_flush(true);<🎜> <🎜>echo str_pad(" ", 256);<🎜> <🎜> <🎜> <🎜>if(intval($_POST['num']>0)) $num=intval($_POST['num']); //Quantity if(intval($_POST['point']>0)) $point=intval($_POST['point']); //Points if(intval($_POST['batch']>0)) $batch=intval($_POST['batch']); //Batch number if(($_POST['ym']!="")) $ym=$_POST['ym']; //Year and month of release else $ym=date('ym'); if($num==0) return; $num=$num*100; //The number of cards, that is, the number of records echo "

Start ".date("H:i:s")." "; for($i=1;$i<=$num;$i )<🎜> <🎜>{<🎜> <🎜>$sn=sprintf(" s%s s",$batch,$ym,$i);<🎜> <🎜>$seek=mt_rand(0,9999).mt_rand(0,9999).mt_rand(0,9999); //12 digits<🎜> <🎜>$start=mt_rand(0,20);<🎜> <🎜>$str=strtoupper(substr(md5($seek),$start,12));<🎜> <🎜>$str=str_replace("O",chr(mt_rand(65,78)),$str);<🎜> <🎜>$str=str_replace("0",chr(mt_rand(65,78)),$str);<🎜> <🎜>$row=array('sn'=>$sn,'password'=>$str,'created'=>time(),'point'=>$point); //Check for plagiarism //Add the code to insert data here. print_r($row); } echo " end ".date("H:i:s").""; printf("
Successfully generated: %s passwords for %s points

",$num/1e4,$point); return $num; } //End of function $_POST['num']=1; $_POST['point']=10; $_POST['batch']=10; $_POST['ym']='1405'; echo MakeCard(); ?>

Method 2:

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

$numLen=16;

$pwdLen=10;

$c=100;//生成100组卡号密码

$sNumArr=range(0,9);

$sPwdArr=array_merge($sNumArr,range('A','Z'));

$cards=array();

for($x=0;$x< $c;$x ){

$tempNumStr=array();

for($i=0;$i< $numLen;$i ){

$tempNumStr[]=array_rand($sNumArr);

}

$tempPwdStr=array();

for($i=0;$i< $pwdLen;$i ){

$tempPwdStr[]=$sPwdArr[array_rand($sPwdArr)];

}

$cards[$x]['no']=implode('',$tempNumStr);

$cards[$x]['pwd']=implode('',$tempPwdStr);

}

array_unique($cards);

print_r($cards);

?>

1

2 3

45 6 7 8 9 10
11
12
13 14 15 16 17 18 19 20 21 22 23
<🎜>$numLen=16;<🎜> <🎜>$pwdLen=10;<🎜> <🎜>$c=100;//Generate 100 sets of card number passwords<🎜> <🎜>$sNumArr=range(0,9);<🎜> <🎜>$sPwdArr=array_merge($sNumArr,range('A','Z'));<🎜> <🎜> <🎜> <🎜>$cards=array();<🎜> <🎜>for($x=0;$x< $c;$x ){<🎜> <🎜>$tempNumStr=array();<🎜> <🎜>for($i=0;$i< $numLen;$i ){<🎜> <🎜>$tempNumStr[]=array_rand($sNumArr);<🎜> <🎜>}<🎜> <🎜>$tempPwdStr=array();<🎜> <🎜>for($i=0;$i< $pwdLen;$i ){<🎜> <🎜>$tempPwdStr[]=$sPwdArr[array_rand($sPwdArr)];<🎜> <🎜>}<🎜> <🎜>$cards[$x]['no']=implode('',$tempNumStr);<🎜> <🎜>$cards[$x]['pwd']=implode('',$tempPwdStr);<🎜> <🎜>}<🎜> <🎜>array_unique($cards);<🎜> <🎜>print_r($cards);<🎜> <🎜>?>
The above is the entire content of this article, I hope you all like it. http://www.bkjia.com/PHPjc/1000077.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1000077.htmlTechArticleWrite php code to batch generate unique card number passwords. This article shares with you a very practical code. In the project It is often used and can generate unique card numbers and passwords in batches...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn