<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.uniqid.php',
    1 => 'uniqid',
    2 => 'Generate a time-based identifier',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Misc. Functions',
  ),
  'prev' => 
  array (
    0 => 'function.time-sleep-until.php',
    1 => 'time_sleep_until',
  ),
  'next' => 
  array (
    0 => 'function.unpack.php',
    1 => 'unpack',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/misc/functions/uniqid.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.uniqid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">uniqid</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">uniqid</span> &mdash; <span class="dc-title">Generate a time-based identifier</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.uniqid-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>uniqid</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$prefix</code><span class="initializer"> = &quot;&quot;</span></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$more_entropy</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Gets an identifier based on the current time with microsecond precision,
   prefixed with the given <code class="parameter">prefix</code> and optionally
   appending a randomly generated value.
  </p>
  <div class="caution"><strong class="caution">Caution</strong>
 <p class="para">
  This function does not generate cryptographically secure values, and <em>must not</em>
  be used for cryptographic purposes, or purposes that require returned values to be unguessable.
 </p>
 <p class="para">
  If cryptographically secure randomness is required, the <span class="classname"><a href="class.random-randomizer.php" class="classname">Random\Randomizer</a></span> may be
  used with the <span class="classname"><a href="class.random-engine-secure.php" class="classname">Random\Engine\Secure</a></span> engine. For simple use cases, the <span class="function"><a href="function.random-int.php" class="function">random_int()</a></span>
  and <span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span> functions provide a convenient and secure <abbr title="Application Programming Interface">API</abbr> that is backed by
  the operating system’s <abbr title="Cryptographically Secure PseudoRandom Number Generator">CSPRNG</abbr>.
 </p>
</div>
  <div class="warning"><strong class="warning">Warning</strong>
    <p class="para">
     This function does not guarantee the uniqueness of the return
     value because the value is based on the current time in microseconds
     or the current time with a small amount of random data appended
     if <code class="parameter">more_entropy</code> is <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
    </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.uniqid-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">prefix</code></dt>
     <dd>
      <p class="para">
       Can be useful, for instance, if you generate identifiers
       simultaneously on several hosts that could generate the
       same identifier at the same microsecond. (This can happen
       even on a single host if the system clock is moved backwards,
       such as by an NTP adjustment.)
      </p>
      <p class="para">
       With an empty <code class="parameter">prefix</code>, the returned string will
       be 13 characters long.  If <code class="parameter">more_entropy</code> is
       <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, it will be 23 characters.
      </p>
     </dd>
    
    
     <dt><code class="parameter">more_entropy</code></dt>
     <dd>
      <p class="para">
       If set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, <span class="function"><strong>uniqid()</strong></span> will add additional
       entropy (using the combined linear congruential generator) at the end
       of the return value, which increases the likelihood that the result
       will be unique.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.uniqid-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns timestamp based identifier as a string.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
     This function does not guarantee the uniqueness of the return value.
   </p>
  </div>
 </div>


 <div class="refsect1 examples" id="refsect1-function.uniqid-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>uniqid()</strong></span> Example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* A uniqid, like: 4b3403665fea6 */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid(): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">/* We can also prefix the uniqid, this the same as <br /> * doing:<br /> *<br /> * $uniqid = $prefix . uniqid();<br /> * $uniqid = uniqid($prefix);<br /> */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('php_'): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">(</span><span style="color: #DD0000">'php_'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* We can also activate the more_entropy parameter, which is <br /> * required on some systems, like Cygwin. This makes uniqid()<br /> * produce a value like: 4b340550242239.64159797<br /> */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('', true): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.uniqid-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Under Cygwin, the <code class="parameter">more_entropy</code> must be set 
    to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> for this function to work.
   </p>
  </p></blockquote>

 </div>

 <div class="refsect1 seealso" id="refsect1-function.uniqid-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.random-bytes.php" class="function" rel="rdfs-seeAlso">random_bytes()</a> - Get cryptographically secure random bytes</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>