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? 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. 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 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. 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* 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()); 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. 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. 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! Link to comment https://forums.phpfreaks.com/topic/128435-solved-unique-id-generator/#findComment-665624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.