note 80419 added to function.uniqid
| From: | nodkzatmaildotru at osu1 dot php dot net | Date: | Tue, 15 Jan 2008 10:00:57 +0000 |
| Subject: | note 80419 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135110@lists.php.net to get a copy of this message | ||
I use such UUID (it not RFC!!!)
(server_id)-(clientIP)-(unixtime)-(milliseconds)-(random)
I can easyly determine which server at which time and who initiate creating of object.
<?php
$u=uuid(); // 0001-7f000001-478c8000-4801-47242987
echo $u;
echo "<br>";
print_r(uuidDecode($u)); // Array ( [serverID] => 0001 [ip] => 127.0.0.1 [unixtime] =>
1200390144 [micro] => 0.28126525878906 )
function uuid($serverID=1)
{
$t=explode(" ",microtime());
return sprintf( '%04x-%08s-%08s-%04s-%04x%04x',
$serverID,
clientIPToHex(),
substr("00000000".dechex($t[1]),-8), // get 8HEX of unixtime
substr("0000".dechex(round($t[0]*65536)),-4), // get 4HEX of microtime
mt_rand(0,0xffff), mt_rand(0,0xffff));
}
function uuidDecode($uuid) {
$rez=Array();
$u=explode("-",$uuid);
if(is_array($u)&&count($u)==5) {
$rez=Array(
'serverID'=>$u[0],
'ip'=>clientIPFromHex($u[1]),
'unixtime'=>hexdec($u[2]),
'micro'=>(hexdec($u[3])/65536)
);
}
return $rez;
}
function clientIPToHex($ip="") {
$hex="";
if($ip=="") $ip=getEnv("REMOTE_ADDR");
$part=explode('.', $ip);
for ($i=0; $i<=count($part)-1; $i++) {
$hex.=substr("0".dechex($part[$i]),-2);
}
return $hex;
}
function clientIPFromHex($hex) {
$ip="";
if(strlen($hex)==8) {
$ip.=hexdec(substr($hex,0,2)).".";
$ip.=hexdec(substr($hex,2,2)).".";
$ip.=hexdec(substr($hex,4,2)).".";
$ip.=hexdec(substr($hex,6,2));
}
return $ip;
}
?>
----
Server IP: 195.54.192.44
Probable Submitter: 212.154.136.225
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/80419
Del: integrated -- https://master.php.net/note/delete/80419/integrated
Del: useless -- https://master.php.net/note/delete/80419/useless
Del: bad code -- https://master.php.net/note/delete/80419/bad+code
Del: spam -- https://master.php.net/note/delete/80419/spam
Del: non-english -- https://master.php.net/note/delete/80419/non-english
Del: in docs -- https://master.php.net/note/delete/80419/in+docs
Del: other reasons-- https://master.php.net/note/delete/80419
Reject -- https://master.php.net/note/reject/80419
Search -- https://master.php.net/manage/user-notes.php