Re: [RFC] Make uniqid() more unique
| From: | Pierre Joye | Date: | Sat, 10 Sep 2016 03:35:43 +0000 |
| Subject: | Re: [RFC] Make uniqid() more unique | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95890@lists.php.net to get a copy of this message | ||
Hi,
On Sep 9, 2016 7:50 PM, "Niklas Keller" <me@kelunik.com> wrote:
>
> 2016-09-09 13:48 GMT+02:00 Yasuo Ohgaki <yohgaki@ohgaki.net>:
>
> > Hi all,
> >
> > On Fri, Sep 9, 2016 at 8:18 PM, Arvids Godjuks <arvids.godjuks@gmail.com
>
> > wrote:
> > >
> > > Hm, without "true" you get 13 chars, with "true" - 20+.
> >
> > Sorry. It's
> >
> > $ php -r 'var_dump(uniqid(), uniqid("", true));'
> > string(13) "57d29c20c04c3"
> > string(23) "57d29c20c04c50.55225401"
> >
> > I misread sprintf format.
> >
> > Anyway, we may use extra 10 chars to make it more random if it should
> > keep compatibility.
>
>
> That still breaks BC as the value is now longer than before.
>
>
> > It seems uniqid() is popular for test scripts, so
> > it would be preferred keeping it.
>
>
> Nobody said it should be removed now. Maybe in the future. But you might
as
> well just use bin2hex(random_bytes(16)).
Or uuid. This why this standard exists. I would recommend to move to that
instead of trying to reinvent the wheel.
https://github.com/ramsey/uuid is pretty good.
Cheers
Pierre