File: uniqid.xml

package info (click to toggle)
php-doc 20081024-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 57,752 kB
  • ctags: 3,858
  • sloc: xml: 686,554; php: 19,446; perl: 610; cpp: 500; makefile: 336; sh: 114; awk: 28
file content (142 lines) | stat: -rw-r--r-- 3,721 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<refentry xml:id="function.uniqid" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>uniqid</refname>
  <refpurpose>Generate a unique ID</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>string</type><methodname>uniqid</methodname>
   <methodparam choice="opt"><type>string</type><parameter>prefix</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>more_entropy</parameter></methodparam>
  </methodsynopsis>
  <para>
   Gets a prefixed unique identifier based on the current time in
   microseconds. 
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>prefix</parameter></term>
     <listitem>
      <para>
       Can be useful, for instance, if you generate identifiers
       simultaneously on several hosts that might happen to generate the
       identifier at the same microsecond.
      </para>
      <para>
       With an empty <parameter>prefix</parameter>, the returned string will
       be 13 characters long.  If <parameter>more_entropy</parameter> is
       &true;, it will be 23 characters.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>more_entropy</parameter></term>
     <listitem>
      <para>
       If set to &true;, <function>uniqid</function> will add additional
       entropy (using the combined linear congruential generator) at the end
       of the return value, which should make the results more unique.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns the unique identifier, as a string.
  </para>
 </refsect1>

 <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());

// better, difficult to guess
$better_token = md5(uniqid(rand(), true));
?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>5.0.0</entry>
       <entry>
        The <parameter>prefix</parameter> parameter was made optional.
       </entry>
      </row>
      <row>
       <entry>4.3.1</entry>
       <entry>
        The limit of 114 characters long for <parameter>prefix</parameter>
        was raised.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </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
-->