Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 6482

php-manual-en-5.5.7-1.mga4.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)</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"> = false</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Gets a prefixed unique identifier based on the current time in
   microseconds. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.uniqid-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">prefix</code></em></span>
     <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 <em><code class="parameter">prefix</code></em>, the returned string will
       be 13 characters long.  If <em><code class="parameter">more_entropy</code></em> is
       <strong><code>TRUE</code></strong>, it will be 23 characters.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">more_entropy</code></em></span>
     <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>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.uniqid-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the unique identifier, as a string.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.uniqid-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3788">
    <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 changelog" id="refsect1-function.uniqid-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.0.0</td>
       <td>
        The <em><code class="parameter">prefix</code></em> parameter was made optional.
       </td>
      </tr>

      <tr>
       <td>4.3.1</td>
       <td>
        The limit of 114 characters long for <em><code class="parameter">prefix</code></em>
        was raised.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.uniqid-notes">
  <h3 class="title">Notes</h3>
  <div class="caution"><strong class="caution">Caution</strong>
   <p class="para">
    This function does not generate cryptographically secure tokens, 
    in fact without being passed any additional parameters the return 
    value is little different from  <span class="function"><a href="function.microtime.html" class="function">microtime()</a></span>. If 
    you need to generate cryptographically secure tokens use 
     <span class="function"><a href="function.openssl-random-pseudo-bytes.html" class="function">openssl_random_pseudo_bytes()</a></span>.
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Under Cygwin, the <em><code class="parameter">more_entropy</code></em> 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>