Home > Backend Development > PHP Tutorial > How to generate a locally unique identifier LUID using php

How to generate a locally unique identifier LUID using php

WBOY
Release: 2016-07-25 09:08:14
Original
918 people have browsed it
  1. /**
  2. * Returns a string that is unique in the local system.
  3. * Returns a 32-character string in the form of '7dac352074f221f3edc74d265c65a636', or 'd198d8fc56ffed627f3f8313d6f06acf'
  4. */
  5. function LUID(){
  6. return MD5(microtime());
  7. }
  8. ?>
Copy code

In fact, just One line: return MD5(microtime());

Logically, the string returned by microtime() is already unique. After testing, even if microtime() is executed continuously, the return value will have a difference of more than 100us. When the user clicks, it will be transmitted on the network and then sent to the server. The processing interval is much more than a few tens of ms, and adding md5 will only complicate the results.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template