note 104868 added to function.uniqid
| From: | mmw at example dot com | Date: | Tue, 12 Jul 2011 20:22:16 +0000 |
| Subject: | note 104868 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181444@lists.php.net to get a copy of this message | ||
function uuidgen($sha1 = false, $exec = true) {
$stdout = array();
$cmd = "uuidgen 2>&1";
$status = -100;
if ($exec) {
exec($cmd, $stdout, $status);
}
if ($status == 0 && count($stdout)) {
$uuid = $stdout[0];
} else {
$md5 = strtoupper(md5(uniqid(microtime(true), true)));
$uuid = sprintf("%04s%04s-%04s-%04s-%04s-%04s%04s%04s",
$md5[0].$md5[1].$md5[2].$md5[3],
$md5[4].$md5[5].$md5[6].$md5[7],
$md5[8].$md5[9].$md5[10].$md5[11],
$md5[12].$md5[13].$md5[14].$md5[15],
$md5[16].$md5[17].$md5[18].$md5[19],
$md5[20].$md5[21].$md5[22].$md5[23],
$md5[24].$md5[25].$md5[26].$md5[27],
$md5[28].$md5[29].$md5[30].$md5[31]
);
}
if ($sha1) {
$uuid = sha1($uuid);
}
return $uuid;
}
a simple thought which may satisfy many of you 8-), the md5 char array; just to be verbose 8-)
----
Server IP: 69.147.83.197
Probable Submitter: 173.228.86.18
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/104868
Del: integrated -- https://master.php.net/note/delete/104868/integrated
Del: useless -- https://master.php.net/note/delete/104868/useless
Del: bad code -- https://master.php.net/note/delete/104868/bad+code
Del: spam -- https://master.php.net/note/delete/104868/spam
Del: non-english -- https://master.php.net/note/delete/104868/non-english
Del: in docs -- https://master.php.net/note/delete/104868/in+docs
Del: other reasons-- https://master.php.net/note/delete/104868
Reject -- https://master.php.net/note/reject/104868
Search -- https://master.php.net/manage/user-notes.php