Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 6989

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generate a unique ID</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.time-sleep-until.html">time_sleep_until</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.unpack.html">unpack</a></div>
 <div class="up"><a href="ref.misc.html">Misc. Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.uniqid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">uniqid</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">uniqid</span> &mdash; <span class="dc-title">Generate a unique ID</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.uniqid-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>uniqid</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$prefix</code><span class="initializer"> = &quot;&quot;</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$more_entropy</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Gets a prefixed unique identifier based on the current time in
   microseconds.
  </p>
  <div class="caution"><strong class="caution">Caution</strong><p class="para">This function does not
generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a
cryptographically secure value, consider using <span class="function"><a href="function.random-int.html" class="function">random_int()</a></span>, <span class="function"><a href="function.random-bytes.html" class="function">random_bytes()</a></span>, or
<span class="function"><a href="function.openssl-random-pseudo-bytes.html" class="function">openssl_random_pseudo_bytes()</a></span> instead.</p></div>
  <div class="warning"><strong class="warning">Warning</strong>
    <p class="para">
     This function does not guarantee uniqueness of return
     value. Since most systems adjust system clock by NTP or like,
     system time is changed constantly. Therefore, it is possible that
     this function does not return unique ID for the
     process/thread. Use <code class="parameter">more_entropy</code> to
     increase likelihood of uniqueness.
    </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 might happen to generate the
       identifier at the same microsecond.
      </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>TRUE</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>TRUE</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 unique identifier as a string.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
     This function tries to create unique identifier, but it does not
     guarantee 100% uniqueness of 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-4680">
    <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">/*&nbsp;A&nbsp;uniqid,&nbsp;like:&nbsp;4b3403665fea6&nbsp;*/<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid():&nbsp;%s\r\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">uniqid</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">/*&nbsp;We&nbsp;can&nbsp;also&nbsp;prefix&nbsp;the&nbsp;uniqid,&nbsp;this&nbsp;the&nbsp;same&nbsp;as&nbsp;<br />&nbsp;*&nbsp;doing:<br />&nbsp;*<br />&nbsp;*&nbsp;$uniqid&nbsp;=&nbsp;$prefix&nbsp;.&nbsp;uniqid();<br />&nbsp;*&nbsp;$uniqid&nbsp;=&nbsp;uniqid($prefix);<br />&nbsp;*/<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('php_'):&nbsp;%s\r\n"</span><span style="color: #007700">,&nbsp;</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">/*&nbsp;We&nbsp;can&nbsp;also&nbsp;activate&nbsp;the&nbsp;more_entropy&nbsp;parameter,&nbsp;which&nbsp;is&nbsp;<br />&nbsp;*&nbsp;required&nbsp;on&nbsp;some&nbsp;systems,&nbsp;like&nbsp;Cygwin.&nbsp;This&nbsp;makes&nbsp;uniqid()<br />&nbsp;*&nbsp;produce&nbsp;a&nbsp;value&nbsp;like:&nbsp;4b340550242239.64159797<br />&nbsp;*/<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('',&nbsp;true):&nbsp;%s\r\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">uniqid</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</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>TRUE</code></strong> for this function to work.
   </p>
  </p></blockquote>

 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.time-sleep-until.html">time_sleep_until</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.unpack.html">unpack</a></div>
 <div class="up"><a href="ref.misc.html">Misc. Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>