note 96549 added to function.uniqid
| From: | Robin at osu1 dot php dot net | Date: | Thu, 04 Mar 2010 15:20:47 +0000 |
| Subject: | note 96549 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166661@lists.php.net to get a copy of this message | ||
As others below note, without prefix and without "added entropy", this function simply
returns the UNIX timestamp with added microsecond counter as a hex number; it's more or less
just microtime(), in hexit form.
A longer and more diverse unique id in the same hexit scheme can be achieved by instead digesting
uniqid() (or a series of mt_rand(), f.e.) through md5() or sha1():
<?php
$unique = md5( uniqid() ); // 32 characters long
$unique = sha1( uniqid() ); // 40 characters long
?>
Also worth to note is that since microtime() only works on systems that have gettimeofday() present,
which Windows natively DOES NOT, uniqid() might yield just the single-second-resolution UNIX
timestamp in a Windows environment.
----
Server IP: 194.236.124.41
Probable Submitter: 83.227.160.33
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/96549
Del: integrated -- https://master.php.net/note/delete/96549/integrated
Del: useless -- https://master.php.net/note/delete/96549/useless
Del: bad code -- https://master.php.net/note/delete/96549/bad+code
Del: spam -- https://master.php.net/note/delete/96549/spam
Del: non-english -- https://master.php.net/note/delete/96549/non-english
Del: in docs -- https://master.php.net/note/delete/96549/in+docs
Del: other reasons-- https://master.php.net/note/delete/96549
Reject -- https://master.php.net/note/reject/96549
Search -- https://master.php.net/manage/user-notes.php