Quantcast
Channel: User Ja͢ck - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by Ja͢ck for how to generate unique id in php based on current data and time?

$
0
0

With PHP 7 you can use this to generate a sufficiently random value based on the current timestamp:

$s = time() . bin2hex(random_bytes(10));

Do note that after 265 years (starting with 11 digits in 2286) the timestamp would get another digit, and sorting order will be off; if your code is expected to survive for that long, you may want to consider some padding.

Old answer

You can use a combination of uniqid() and time() like so:

$s = uniqid(time(), true);

Example output:

1346136883503c6b3330caf5.19553126

Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>