note 124072 added to function.uniqid
| From: | DimeCadmium@php.net | Date: | Thu, 25 Jul 2019 19:00:31 +0000 |
| Subject: | note 124072 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211701@lists.php.net to get a copy of this message | ||
Most of these notes are grossly wrong.
First: you probably shouldn't be using uniqid at all. I can't think of a good reason to
use it. Maybe to use as an identifier for a particular run of your script in logging, where you
don't particularly care if there's a collision? I don't know.
Second: don't rely on the output of uniqid to be, in any way, unique. This will break if you
use it twice in quick succession, or if you have two different users at the same time, or if the
phase of the moon is wrong.
Third: to nodkz who wrote the clientIPToHex function - you reinvented so many wheels.
bin2hex(inet_pton($ip)) will do the same thing.
Fourth: do not use random bytes for a unique identifier (like hackan suggests). That only serves to
virtually guarantee that you will eventually have a collision. (You can use random bytes, and get
another set of random bytes if there's a collision... but it's a lot easier to just use a
sequential identifier like you should, possibly along with a random key)
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 24.27.57.202)
----
Manual Page -- http://php.net/manual/en/function.uniqid.php
Edit -- https://master.php.net/note/edit/124072
Del: integrated -- https://master.php.net/note/delete/124072/integrated
Del: useless -- https://master.php.net/note/delete/124072/useless
Del: bad code -- https://master.php.net/note/delete/124072/bad+code
Del: spam -- https://master.php.net/note/delete/124072/spam
Del: non-english -- https://master.php.net/note/delete/124072/non-english
Del: in docs -- https://master.php.net/note/delete/124072/in+docs
Del: other reasons-- https://master.php.net/note/delete/124072
Reject -- https://master.php.net/note/reject/124072
Search -- https://master.php.net/manage/user-notes.php