note 106427 added to function.uniqid
| From: | previous-sample-removed at osu1 dot php dot net | Date: | Wed, 09 Nov 2011 03:35:30 +0000 |
| Subject: | note 106427 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184342@lists.php.net to get a copy of this message | ||
function uuidgen($sha1 = false, $exec = true) {
$stdout = array();
$cmd = "uuidgen 2>&1";
$status = -100;
$uuid = null;
$haveUUID = false;
if ($exec) {
exec($cmd, $stdout, $status);
}
if ($status == 0 && count($stdout)) {
$uuid = $stdout[0];
if (strlen($uuid) == 36) {
$haveUUID = true;
$uuid = strtoupper($uuid);
}
}
if (!$haveUUID) {
// please use md5($input, true) just an a verbose example
/*
$r = unpack('v*', $md5_raw);
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
$r[1], $r[2], $r[3], $r[4] & 0x0fff | 0x4000,
$r[5] & 0x3fff | 0x8000, $r[6], $r[7], $r[8]);
*/
$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;
}
----
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/106427
Del: integrated -- https://master.php.net/note/delete/106427/integrated
Del: useless -- https://master.php.net/note/delete/106427/useless
Del: bad code -- https://master.php.net/note/delete/106427/bad+code
Del: spam -- https://master.php.net/note/delete/106427/spam
Del: non-english -- https://master.php.net/note/delete/106427/non-english
Del: in docs -- https://master.php.net/note/delete/106427/in+docs
Del: other reasons-- https://master.php.net/note/delete/106427
Reject -- https://master.php.net/note/reject/106427
Search -- https://master.php.net/manage/user-notes.php