Php code for batch generation of non-repeated card numbers and passwords

Source: Internet
Author: User

Php code for batch generation of non-repeated card numbers and passwords

This article will share with you a very practical code that is frequently used in projects. You can generate two non-repeated card numbers and passwords in batches. For more information, see.

When it hurts, by the way, I have strengthened some of my skills in PHP's array manipulation. I wrote the following small code, which can randomly generate the array corresponding to the card number and password, and automatically repeat, without any ideas.

?

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

<? Php header ('content-Type: text/html; charset = UTF-8 ');

Function MakeCard ()

{

Set_time_limit (0 );

 

// Process the 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']; // date of release

Else $ ym = date ('ymm ');

 

If ($ num = 0) return;

 

$ Num = $ num * 100; // number of cards, that is, the number of records

 

Echo "<p> Start". date ("H: I: s ")."";

 

For ($ I = 1; $ I <= $ num; $ I ++)

{

$ Sn = sprintf ("% 02 s % 06 s", $ batch, $ ym, $ I );

$ Seek = mt_rand (). mt_rand (). mt_rand (); // 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 );

// Re-Query

// Add the data insertion code here.

Print_r ($ row );

}

Echo "end". date ("H: I: s ")."";

Printf ("<br> successfully generated: % s passwords at % s </p>", $ num/1e4, $ point );

Return $ num;

} // Function end

 

$ _ POST ['num'] = 1;

$ _ POST ['point'] = 10;

$ _ POST ['batch'] = 10;

$ _ POST ['ym'] = '000000 ';

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

<? Php

$ NumLen = 16;

$ PwdLen = 10;

$ C = 100; // generate the 100 group card number Password

$ 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 all the content of this article. I hope you will like it.

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.