note 45662 deleted from function.microtime by aidan
| From: | aidan@php.net | Date: | Tue, 14 Sep 2004 15:34:13 +0000 |
| Subject: | note 45662 deleted from function.microtime by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76678@lists.php.net to get a copy of this message | ||
Note Submitter: phpContrib (A T) esurfers d o t c o m
----
Do you need a "good" session id to save and retrieve user data?
You can get a BIG int containing the timestamp from the Unix Epoch in microseconds: the number of
MICROseconds since 1/1/1970
You can use this (of course it's not the only way):
<?php
list ($usec, $sec) = explode (" ", microtime());
$sid = ($sec) . str_pad ((int)($usec * 1000000), 6, "0", STR_PAD_LEFT);
//...
?>
It will create a string consisting of only digits like this: "1095173921749619".
There will not be two connections sharing this number, but if you want you can add some random at
the end:
<?php
list ($usec, $sec) = explode (" ", microtime());
$sid = ($sec) . str_pad ((int)($usec * 1000000), 6, "0", STR_PAD_LEFT). str_pad (rand (0,
999), 3, "0", STR_PAD_LEFT);
//...
?>
and for even better safety append the client IP at the end.