tinker Posted January 17, 2008 Share Posted January 17, 2008 I'm after something truly unique about the system to help generate a unique id. I'm may going over the top with worst case scenario's but... This is what ii've got so far: srand( (double)microtime() * 1000); print "\$id = ".md5(php_uname().uniqid(rand(), true))."<br>"; But On Unix' date=' the output reverts to displaying the operating system information PHP was built on if it cannot determine the currently running OS.[/quote'] Which leads me to believe that this cannot be relied upon to be unique in all instances. Therefore what else can you suggest that will truly be unique to a particular system? Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/ Share on other sites More sharing options...
trq Posted January 17, 2008 Share Posted January 17, 2008 The simple fact that your using rand prevents your code from ever being truly unique. There is always chance that your code can produce the same code more than once. Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/#findComment-441901 Share on other sites More sharing options...
tinker Posted January 17, 2008 Author Share Posted January 17, 2008 that's exactly why I wanted a prefix and thought of uname, but even that seem's to have a flaw. Two machine's setup identically, perfectly in sync, issuing an id simultaneously to the micro second (which is why I use microtime to seed srand, because that adds a second call to microtime (e.g. uniqid also uses)) and if uname fails then because of same installation it'll output same on both... what else is available? Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/#findComment-441916 Share on other sites More sharing options...
trq Posted January 17, 2008 Share Posted January 17, 2008 Firstly why do you need unique random numbers presumably accross different installs of this application (ie:different machines)? Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/#findComment-441919 Share on other sites More sharing options...
tinker Posted January 17, 2008 Author Share Posted January 17, 2008 i've been asked to accommodate the possibility that at some point that a cms instance could be installed on numerous servers, all providing access to the same site, just from different routed access points to a network, or even from different networks (is it distributed servers). It is possible that they could query a centralised id generation script, but that's extra overhead and depends upon a guaranteed route there, so i'm looking for something internal, i.e. can I access some internal system entropy, say from '/dev/urandom', i'm not guaranteed access to openssl (which has a good random number generator), and i've also been looking at PHP's 'mt_rand()'. Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/#findComment-441937 Share on other sites More sharing options...
tinker Posted January 17, 2008 Author Share Posted January 17, 2008 Just reading aother post here and had the thought that maybe I could rely upon $_SERVER['REMOTE_ADDR'] and $_SERVER['REMOTE_PORT'], not so sure about $_SERVER['REQUEST_TIME'] and was obviously avoiding sess_id. what do you think? Quote Link to comment https://forums.phpfreaks.com/topic/86485-freak-or-unique/#findComment-441949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.