PHP registration code/serial number generation instance program

Source: Internet
Author: User
Tags random seed
A product was developed yesterday and requires that a registration code serial number be generated by the general background of the website, which is then generated in the format of 573-225-374-118 and is unique in the database, next I will record all the information I found and I wrote myself. The principle is to generate mt... A product was developed yesterday and requires that a registration code/serial number be generated by the general background of the website, and then generated in the format of 573-225-374-118, which is unique in the database, next I will record all the information I found and I wrote myself.

The principle is to generate mt_rand random seed and then use the relevant functions for read operations.

Example 1 code:

 '; Return $ serialNumber;} echo snMaker (); /*** replace a part of a string with a specific character * @ param str or int $ string to be processed by str * @ param str or int $ * @ param int $ start keep the first few characters * @ param int $ end keep the last few characters */function hideString ($ str = 'hello ', $ to = '*', $ start = 1, $ end = 0) {$ lenth = strlen ($ str)-$ start-$ end; $ lenth = ($ lenth <0 )? 0: $ lenth; $ to = str_repeat ($ to, $ lenth); $ str = substr_replace ($ str, $ to, $ start, $ lenth); return $ str ;} echo hideString ();?>

Example 2: generate the registration code/serial number. the reference content is as follows:

 

The execution of the program will generate the cd_key.txt file, which contains a verification code similar to the following, which is referenced below:

573-225-374-118,691-553-280-280,969-594-607-211,251-575-776-563,280--289-739-533...

In this way, we fully achieve our goal. you can also save the above random strings to the database for convenient calling and flexible setting of the above variables, you can generate 16-bit and 20-bit verification codes. if you are interested, you can also write verification codes similar to XDF8F-ADE89-D0J5C-4RTFG.


Link to this article:

Add to favorites ^ please keep the tutorial address.

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.