Hi,
This is a weird issue. Every once in awhile, my code will return the exact same "$linkId" value for the following:
$linkId = substr(md5(uniqid(rand(), true) + $user_id), 0, 20) . '-' . substr(md5(uniqid(rand(), true) + $user_id), 13, 32);
It always returns: 9517fd0bf8faa655990a-655990a4dffe358e13e
I have no clue as to why this specific code would always return the same value, even for different users. This is a HUGE issue for me. Thanks for the help!
PHP md5() problem
Moderator: General Moderators
Re: PHP md5() problem
It's always that regardless of what $user_id is.
Here we go...
always returns "INF". Remove the "+ $user_id" and it'll work.
EDIT: I do wonder though.. what are you trying to do? What's wrong with just using uniqid() on it's own? Or an MD5 hash of it. Why are you taking two halves of two random hashes? That won't make it any more random.
Here we go...
Code: Select all
uniqid(rand(), true) + $user_idEDIT: I do wonder though.. what are you trying to do? What's wrong with just using uniqid() on it's own? Or an MD5 hash of it. Why are you taking two halves of two random hashes? That won't make it any more random.
Re: PHP md5() problem
Thanks for your reply!
The $user_id is the unique user ID for each user so I thought it may help to make it a little more random. I just combined two hashes cause I wanted it 40 chars long.
BUT, I use that same code around the entire site to generate special little unique hash codes and they always seems to work
Its so random though. Sometimes it will work and give different results, and sometimes, no matter who the user is, will generate the same result.
The $user_id is the unique user ID for each user so I thought it may help to make it a little more random. I just combined two hashes cause I wanted it 40 chars long.
BUT, I use that same code around the entire site to generate special little unique hash codes and they always seems to work
Its so random though. Sometimes it will work and give different results, and sometimes, no matter who the user is, will generate the same result.
Re: PHP md5() problem
If you want 40 chars, use sha1() instead of md5()