PHP Developers Cookbook (2nd Edition)
Technique
You can use uniqid() , getmypid() , md5() , and microtime () to generate a random ID: <?php $id = md5(uniqid(microtime(), 1)) . getmypid(); ?> Comments
In this example, the getmypid() function is optional ”it's there to make sure that IDs generated by different server processes are not the same. But because md5() here depends on uniqid() , which in turn depends on microtime() , there is a very, very slim chance of ever generating the same ID. |