Re: Unique ID - again
| From: | Richard Davey | Date: | Thu, 12 Feb 2004 11:07:20 +0000 |
| Subject: | Re: Unique ID - again | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177496@lists.php.net to get a copy of this message | ||
Hello Alex,
Thursday, February 12, 2004, 11:00:41 AM, you wrote:
A> I'm using usual md5(microtime()); to create IDs, but now I've encountered a
A> problem with that. I need to create explicitly 6 digit unique
A> number(decimal). Yes, I know I can use for/while loop to fill a string with
A> digits, but is it ABSOLUTELY sure that the random will never return same
A> number when seed is microtime()? It is very important as the number will
A> identify a bank transfer...
If the data is so important - why are you restricting it to a 6 digit
key? You should ideally use the uniqid() function perhaps with a
combined lcg entropy at the end. That will give you a 13 character
long unique id - or md5 it for a 32 character one (see the manual for
examples).
A> Is there any other way than checking with all previous IDs? Or some MySQL
A> function to do this for me?
For something so important I would use (a) a longer unique ID and (b)
I'd still run a SQL check to see if the ID has been already used or
not. A simple MySQL count will bring that result back very quickly.
--
Best regards,
Richard mailto:rich@launchcode.co.uk