MySQL (or another SQL database) is the answer. You can check for an existing OR use it's auto_increment or whatever else you like.

Create a field to track all this stuff. There is no other way to guarantee that an ID is unique than to check it against existing. "Random" functions yield random results, so each time, there is ALWAYS a chance of a number being repeated. Microtime works pretty well, but there is STILL a chance two people could have a transaction at the same time. Yes, the odds can be insanely, insanely small for various functions (i.e. MD5) but as you shorten the length of your number, the odds get higher.

And yes, it's important to realize that a 6 digit unique identifier is limited to 1 million possible combinations, not nearly enough for most banks.

I might suggest you do some more PHP learning before you go and develop an online bank application - this stuff is pretty fundamental programming and database concepts. If your overall skill level isn't very high, you're likely to make mistakes, and either have errors, problems in functionality, or, worse, security problems.

-Galen

On Feb 12, 2004, at 3:00 AM, Alex wrote:

Hi folks,
I'm using usual md5(microtime()); to create IDs, but now I've encountered a
problem with that. I need to create explicitly 6 digit unique
number(decimal). Yes, I know I can use for/while loop to fill a string with
digits, but is it ABSOLUTELY sure that the random will never return same
number when seed is microtime()? It is very important as the number will
identify a bank transfer...


Is there any other way than checking with all previous IDs? Or some MySQL
function to do this for me?


thank you
Alex

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to