limitphp Posted October 23, 2008 Share Posted October 23, 2008 Why would PHP have a uniquid function that creates a uniqueID if they already have a microtime function that truly creates a unqiueID, regardless of time, day, month, or year? This isn't a pressing question, I'm just curious. Quote Link to comment Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond. Microtime doesn't make any attempts to be unique, it simply returns the current time at a microsecond level. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 23, 2008 Share Posted October 23, 2008 that is why i concatenate getmypid() onto microtime for my unique identifiers Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 23, 2008 Share Posted October 23, 2008 that is why i concatenate getmypid() onto microtime for my unique identifiers Clever. Quote Link to comment Share on other sites More sharing options...
limitphp Posted October 23, 2008 Author Share Posted October 23, 2008 Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond. Microtime doesn't make any attempts to be unique, it simply returns the current time at a microsecond level. Yeah, I has posted this before you had replied to the other post pretty much answering the question in this post. Of course, I was thinking, I could just have the ID be auto_increment (1,2,3,4,5,etc).... that insures that every entry is unique. Then just attach some word to the value. So then every value will be example: 1keyword, 2keyword, 3keyword, 4keyword, 5keyword That will insure that people can't guess it.... Then md5 that value and store that in the cookie. It would be unique and it would be very difficult for people to guess it, unless they found out my keyword. Quote Link to comment Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 that is why i concatenate getmypid() onto microtime for my unique identifiers And if both servers have the same PID for php? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 23, 2008 Share Posted October 23, 2008 Every request starts a new child, so the PID would be different for any given microtime(). Quote Link to comment Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Upon closer inspection of getmypid(), I feel stupid Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 23, 2008 Share Posted October 23, 2008 Upon closer inspection of getmypid(), I feel stupid Btw, Rhodesa, that's really ingenious. I'm certainly going to use that next time I need a random ID. Quote Link to comment 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.