I need to assign a unique code, string or intiger, to each user.
The codes have to be absolutly unique and they can be used as a secret referer... for example, if the user X wants to trust user Y, he can just send him his secret code.
I think using a random string is the way to go. But how do i generate uique strings?
I think five or six character long would do it, more than that it can be anoying to the users.
Any ideas?
Thx in advance
how do i genertae unique strings or for user identification.
Moderator: General Moderators
http://www.php.net/uniqid
Given the example, you can cut it down to something like:
Given the example, you can cut it down to something like:
Code: Select all
// no prefix
$token = substr(md5(uniqid()), 0, 6);
// better, difficult to guess
$better_token = substr(md5(uniqid(rand(), true)), 0, 6);What is the context? If this is in reference to storing user data in an RDBMS such as MySQL, you should be utilizing the built in MySQL AUTO_INCREMENT INT type field. Otherwise, you might find this previous thread useful.
nope.. i need unique random strings in order to asign activation codes to the users... i am using the method pointed above.bdlang wrote:What is the context? If this is in reference to storing user data in an RDBMS such as MySQL, you should be utilizing the built in MySQL AUTO_INCREMENT INT type field. Otherwise, you might find this previous thread useful.