svn: /phpdoc/en/trunk/reference/misc/functions/ uniqid.xml

From: Date: Fri, 25 Dec 2009 00:24:47 +0000
Subject: svn: /phpdoc/en/trunk/reference/misc/functions/ uniqid.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-5716@lists.php.net to get a copy of this message
kalle Fri, 25 Dec 2009 00:24:47 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=292616 Log: Fixed bug #50471 (uniqid example is bad) Bug: http://bugs.php.net/50471 (Open) uniqid example is bad Changed paths: U phpdoc/en/trunk/reference/misc/functions/uniqid.xml Modified: phpdoc/en/trunk/reference/misc/functions/uniqid.xml =================================================================== --- phpdoc/en/trunk/reference/misc/functions/uniqid.xml 2009-12-25 00:16:22 UTC (rev 292615) +++ phpdoc/en/trunk/reference/misc/functions/uniqid.xml 2009-12-25 00:24:47 UTC (rev 292616) @@ -62,24 +62,27 @@ <refsect1 role="examples"> &reftitle.examples; <para> - If you need a unique identifier or token and you intend to give - out that token to the user via the network (i.e. session cookies), - it is recommended that you use something along these lines: - </para> - <para> - This will create a 32 character identifier (a 128 bit hex number) - that is extremely difficult to predict. <example> <title><function>uniqid</function> Example</title> <programlisting role="php"> <![CDATA[ <?php -// no prefix -// works only in PHP 5 and later versions -$token = md5(uniqid()); +/* A uniqid, like: 4b3403665fea6 */ +printf("uniqid(): %s\r\n", uniqid()); -// better, difficult to guess -$better_token = md5(uniqid(mt_rand(), true)); +/* We can also prefix the uniqid, this the same as + * doing: + * + * $uniqid = $prefix . uniqid(); + * $uniqid = uniqid($prefix); + */ +printf("uniqid('php_'): %s\r\n", uniqid('php_')); + +/* We can also active the more_entropy parameter, which is + * required on some systems, like Cygwin. This makes uniqid() + * produce a value like: 4b340550242239.64159797 + */ +printf("uniqid('', true): %s\r\n", uniqid('', true)); ?> ]]> </programlisting>

« previous php.doc.cvs (#5716) next »