By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

Unique, secured and short id using php. Possible?

P: 67
Well guys

I need a way to get an unique id using php. For the moment, I have learned that the best way to get an unique ID is to put together time() and server address. Then, for additional security we can use additional strings, sha1, md5, etc.

Problem, the result that I got is quite long. Is it possible to get something that is short, but unique and secured at the same time?

Thanks. :)
Dec 29 '07 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
have you tried using rand()?
Dec 29 '07 #2

P: 67
Thanks mark. But what would be the possibility for two person to get the same number, using rand() only. It seems that there's a danger, isn't it?
Dec 29 '07 #3

P: 67
OK, I am doing it with rand() + mysql_insert_id. :)

Thanks Mark.
Dec 29 '07 #4

Markus
Expert 5K+
P: 6,050
Thanks mark. But what would be the possibility for two person to get the same number, using rand() only. It seems that there's a danger, isn't it?
It is.. but only a little chance that would happen.

And just to make sure that it wasn't a duplicate you could compare the id against the ones already in the db and if there's a match you could create a new one.

OK, I am doing it with rand() + mysql_insert_id. :)

Thanks Mark.
No probs :)
Dec 29 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.