mforan Posted October 14, 2008 Share Posted October 14, 2008 i need to generate a unique id, like a kinda password but one that cannot be multple instances. like a primary key as such, without using auto increment. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/ Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 $letters = range('a', 'z'); shuffle($letters); $new_name = md5(time() . implode('', $letters)); That should be unique enough. Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665529 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 and what if the same generated code appears, that means for example i have 2 of "1" "1".... need to be absouluty sure it cannot be the same as one previously Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665533 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 If you manage to find an intersection with MD5 using the time and random letters, let me know. Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665537 Share on other sites More sharing options...
mforan Posted October 14, 2008 Author Share Posted October 14, 2008 lol i just noticed the time part lol. what if the same time happens *chuckle* Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665539 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 lol i just noticed the time part lol. what if the same time happens *chuckle* Plus random letters? Meh, here: $letters = range('a', 'z'); shuffle($letters); $new_name = md5(time() . implode('', $letters) . rand()); Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665548 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2008 Share Posted October 14, 2008 There are a finite number of md5 values. Multiple starting strings will produce the same md5 result. Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665573 Share on other sites More sharing options...
DarkWater Posted October 14, 2008 Share Posted October 14, 2008 Fair enough, take off the MD5 and that's about as unique as you could ask for. Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665593 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 use a database, and a custom function. store the id's in the DB, then in the function check for the id, if the same run it again! Quote Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665624 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.