Re: Creating Unique Values
| From: | Brian T. Allen | Date: | Wed, 04 Oct 2000 17:38:20 +0000 |
| Subject: | Re: Creating Unique Values | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18630@lists.php.net to get a copy of this message | ||
I wouldn't rely on microtime alone. Granted the chances are VERY slim that
you would ever have 2 simultaneous requests for unique values, but the
possiblitiy exists.
I use:
$uniquevalue = substr(strtoupper(md5(uniqid(rand()))),0,12);
to generate a 12 digit, random string. You can change to 12 to a higher or
lower length as needed. I have found them to be very unique. :}
I generated 5 by echoing out the command one right after the other, and they
are all completely different:
CB6765E57B28
77C658B3870F
EDEAC938B7F2
7AC4071CF40A
5ABBFBD1C47F
To be fool proof you could prepend the microtime value as well.
Suggestions welcome, always looking for a better way.
> Thanks Andrew,
>
> I decided to use the function called erm.... the one that I can never
> remember what it's called without looking in the manual.
>
> microtime(); that's it.
>
> Heres what I did:
>
> $uniquevalue = microtime();
> $uniquevalue = ereg_replace ("\.", "", $uniquevalue); #get rid of the
> period.
> setcookie("cookieset", $uniquevalue);
>
> As microtime() takes it start time from the Unix Epoch (0:00:00 January 1,
> 1970 GMT) the chances of a duplicate are......shall we say slim.
>
> Thanks Mate.
>
> Andy
> M.D.
> www.databasewatch.com
>
> ----- Original Message -----
> From: "Andrew Hill" <ahill@openlinksw.com>
> To: "Andy Woolley" <andy@milonic.com>; <php-general@lists.php.net>
> Sent: Wednesday, October 04, 2000 5:28 PM
> Subject: RE: [PHP] Creating Unique Values
>
>
> > Why don't you just use unix time? This is unique at a certain point,
and
> > will never be repeated.
> >
> > Best regards,
> > Andrew
> > ----------------------------------------------------
> > Andrew Hill
> > Director Technology Evangelism
> > OpenLink Software
> > http://www.openlinksw.com
> > XML & E-Business Infrastructure Technology Provider
> >
> >
> > > -----Original Message-----
> > > From: Andy Woolley [mailto:andy@milonic.com]
> > > Sent: Wednesday, October 04, 2000 12:30 PM
> > > To: php-general@lists.php.net
> > > Subject: [PHP] Creating Unique Values
> > >
> > >
> > > Greetings people,
> > >
> > > Does any have a script that creates unique values in PHP.
> > >
> > > What I need is to do is create a value that will never be used again.
I
> > > think that a combination of date, time, milliseconds and some random
> chars
> > > would be good.
> > >
> > > If I can't get one pre-done, then I'll build one and post it to
> > > you all, it
> > > shouldnt be too complicated to do, but I'm in a rush and I'm
> > > getting lazy in
> > > my old age.
> > >
> > > Cheers Folks.
> > >
> > > Andy Woolley
> > > M.D.
> > > www.databasewatch.com
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-general-help@lists.php.net
> > > To contact the list administrators, e-mail:
php-list-admin@lists.php.net
> > >
> > >
> > >
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net