in a simple user table while adding users, the primary key "userid" field is automatically unique since it increments automatically. But I want to add another alphanumeric field of maximum length of 8 char which will be unique for each user. The following is the function I used. I got it from a website.
function unique_code($limit)
{
return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
}
echo unique_code(8);
Will it always give me unique value? If yes, then it's okay. But if no, is there any other way?