How to generate a recommendation code that is absolutely unique and not easily guessed

Source: Internet
Author: User
Not in the database. not in the database.

Reply content:

Do not go to the database for query

Function makeCode ($ t) {$ time = $ t. mt_rand (); // you can add the thread ID if you think it is not enough. $ Ce = $ time [9]; $ xy = array (); $ xy [0] = array ('A', 'F', 'D', 'X ', 'G', 'H', 'K', 'u', 'P', 'y', 'W', 'P '); $ xy [1] = array ('R', 'G', 'H', 'P', 'X', 'D', 'y', 'u ', 'K', 'F', 'S', 'z ');//... for non-repeated sequences, $ xy [9] = array ('s ', 'K', 'T', 'u', 'e', 'Q', 'V ', 'G', 'R', 'X', 'C', 'J'); $ rb = ''; for ($ I = 12; $ I --;) {$ rb. = $ xy [$ ce] [$ time [$ I];} return $ rb;} makecode (time ())

ForAbsolutely uniqueUseUUID
For example, if you are using a linux system

Echo file_get_contents ('/proc/sys/kernel/random/uuid'); // output: 6c509fc7-328b-4d82-9af8-60c44e7b84b4

After obtaining the preceding unique string, you can process it as needed, for example, intercepting the required length.
PHP generates UUID in many ways. the above method is simple to use and a class library link is recommended.

Generally, the recommendation code does not need to be complicated unless you have a large number of users. I think this is enough for a general company.

Echo substr (md5 (uniqid (mt_rand (1000,999 9), true), 20); // output: 1c7a6db616de
Echo bin2hex (openssl_random_pseudo do_bytes (16); // output: 5a8a80e06ffe44fd0a6931707a26f0cc

You can also freely intercept

Http://hashids.org/

Add a verification code.

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.