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 unique
UseUUID
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.