mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-23 04:18:56 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@132730 c90b9560-bf6c-de11-be94-00142212c4b1
87 lines
2.7 KiB
XML
87 lines
2.7 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.5 $ -->
|
|
<!-- splitted from ./en/functions/misc.xml, last change in rev 1.2 -->
|
|
<refentry id="function.uniqid">
|
|
<refnamediv>
|
|
<refname>uniqid</refname>
|
|
<refpurpose>Generate a unique ID</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>uniqid</methodname>
|
|
<methodparam><type>string</type><parameter>prefix</parameter></methodparam>
|
|
<methodparam choice="opt"><type>bool</type><parameter>lcg</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
<function>uniqid</function> returns a prefixed unique identifier
|
|
based on the current time in microseconds. The prefix can be
|
|
useful for instance if you generate identifiers simultaneously on
|
|
several hosts that might happen to generate the identifier at the
|
|
same microsecond. <parameter>Prefix</parameter> can be up to 114
|
|
characters long.
|
|
</simpara>
|
|
<simpara>
|
|
If the optional <parameter>lcg</parameter> parameter is &true;,
|
|
<function>uniqid</function> will add additional "combined LCG"
|
|
entropy at the end of the return value, which should make the
|
|
results more unique.
|
|
</simpara>
|
|
<simpara>
|
|
With an empty <parameter>prefix</parameter>, the returned string
|
|
will be 13 characters long. If <parameter>lcg</parameter> is
|
|
&true;, it will be 23 characters.
|
|
</simpara>
|
|
<note>
|
|
<simpara>
|
|
The <parameter>lcg</parameter> parameter is only available in
|
|
PHP 4 and PHP 3.0.13 and later.
|
|
</simpara>
|
|
</note>
|
|
<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>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// no prefix
|
|
$token = md5(uniqid(""));
|
|
|
|
// better, difficult to guess
|
|
$better_token = md5(uniqid(rand(), true));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</informalexample>
|
|
</para>
|
|
<simpara>
|
|
This will create a 32 character identifier (a 128 bit hex number)
|
|
that is extremely difficult to predict.
|
|
</simpara>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|