note 69164 added to function.uniqid
| From: | mimec at osu1 dot php dot net | Date: | Fri, 25 Aug 2006 08:36:59 +0000 |
| Subject: | note 69164 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116303@lists.php.net to get a copy of this message | ||
Here is the correct version of a function generating a pseudo-random UUID according to RFC 4122:
<?php
function uuid()
{
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
mt_rand( 0, 0x0fff ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
}
?>
The version and variant is located at the MSB (most significant bits) of the time_hi_and_version and
clock_seq_hi_and_reserved fields, not the LSB as in dholmes version.
----
Server IP: 195.136.184.34
Probable Submitter: 195.82.172.68
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/69164
Del: integrated -- https://master.php.net/note/delete/69164/integrated
Del: useless -- https://master.php.net/note/delete/69164/useless
Del: bad code -- https://master.php.net/note/delete/69164/bad+code
Del: spam -- https://master.php.net/note/delete/69164/spam
Del: non-english -- https://master.php.net/note/delete/69164/non-english
Del: in docs -- https://master.php.net/note/delete/69164/in+docs
Del: other reasons-- https://master.php.net/note/delete/69164
Reject -- https://master.php.net/note/reject/69164
Search -- https://master.php.net/manage/user-notes.php