limitphp Posted October 23, 2008 Share Posted October 23, 2008 When using the function uniqueid, does it create a uniqueid that will never be repeated? In order to do this, I assume it would have to base an id on the date and the time? Also, just to make extra sure, is there any way to store the uniqueID in a table plus have the auto_increment number 1,2,3,etc? In other words, store 1+uniqueID, 2+uniqueID, 3+uniqueID, 4+uniqueID in a table. In doing so, would it be possible to have duplicates? I'm using wamp server phpadmin 5.2.6 Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/ Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 md5(microtime()); will give you a unique ID. The chances that 2 ids are generated at the same microsecond are, well, almost impossible. Yes you can store it in a database as you described...why couldn't you? If you are worried about duplicates and are storing the id in a table, you could always query the table to see if the id already exists, but using the method above with microtime you shouldn't need to do it. Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672883 Share on other sites More sharing options...
limitphp Posted October 23, 2008 Author Share Posted October 23, 2008 md5(microtime()); will give you a unique ID. The chances that 2 ids are generated at the same microsecond are, well, almost impossible. Yes you can store it in a database as you described...why couldn't you? If you are worried about duplicates and are storing the id in a table, you could always query the table to see if the id already exists, but using the method above with microtime you shouldn't need to do it. Is that just based on the time, and not the date? Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672919 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 It is the same as time() (unix timestamp, yes, date and time) except it also has microseconds. Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672937 Share on other sites More sharing options...
limitphp Posted October 23, 2008 Author Share Posted October 23, 2008 It is the same as time() (unix timestamp, yes, date and time) except it also has microseconds. Awesome, thank you kindly! Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672945 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 uniqid() is also based on the date/time to the microsecond, but can add entropy and pseudo-random prefixing. I'd suggest using that, or MySQL's UUID() function over md5( microtime() ) Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672980 Share on other sites More sharing options...
limitphp Posted October 23, 2008 Author Share Posted October 23, 2008 uniqid() is also based on the date/time to the microsecond, but can add entropy and pseudo-random prefixing. I'd suggest using that, or MySQL's UUID() function over md5( microtime() ) So, uniquid() will never ever repeat? And its pretty much the same as microtime? What is entropy and pseudo-random prefixing? Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672991 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Entropy, to put it simply A measure of the level of disorder or randomness in a closed system. Random prefix is just that... a random string that's prefixed in front of the ID... $uid = uniqid( md5(mt_rand()), TRUE ); Though slightly slower, the chances of a collision are extremely unlikely... even if you have several executions in a millisecond. Quote Link to comment https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-672999 Share on other sites More sharing options...
limitphp Posted October 23, 2008 Author Share Posted October 23, 2008 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 https://forums.phpfreaks.com/topic/129794-solved-uniqueid-function-would-uniqueid-ever-be-repeated/#findComment-673024 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.