<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.session.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.session-create-id.php',
    1 => 'session_create_id',
    2 => 'Create new session id',
  ),
  'up' => 
  array (
    0 => 'ref.session.php',
    1 => 'Session Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.session-commit.php',
    1 => 'session_commit',
  ),
  'next' => 
  array (
    0 => 'function.session-decode.php',
    1 => 'session_decode',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/session/functions/session-create-id.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.session-create-id" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_create_id</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.1.0, PHP 8)</p><p class="refpurpose"><span class="refname">session_create_id</span> &mdash; <span class="dc-title">Create new session id</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.session-create-id-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>session_create_id</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="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>session_create_id()</strong></span> is used to create new
   session id for the current session. It returns collision free
   session id.
  </p>
  <p class="para">
   If session is not active, collision check is omitted.
  </p>
  <p class="para">
   Session ID is created according to php.ini settings.
  </p>
  <p class="para">
   It is important to use the same user ID of your web server for GC
   task script. Otherwise, you may have permission problems especially
   with files save handler.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.session-create-id-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">prefix</code></dt>
      <dd>
       <p class="para">
        If <code class="parameter">prefix</code> is specified, new session id
        is prefixed by <code class="parameter">prefix</code>. Not all
        characters are allowed within the session id.  Characters in
        the range <code class="literal">[a-zA-Z0-9,-]</code> are allowed. Maximum length is 256 characters.
       </p> 
      </dd>
     
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-create-id-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   <span class="function"><strong>session_create_id()</strong></span> returns new collision free
   session id for the current session. If it is used without active
   session, it omits collision check.
   On failure, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.session-create-id-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>session_create_id()</strong></span> example with <span class="function"><a href="function.session-regenerate-id.php" class="function">session_regenerate_id()</a></span></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">// My session start function support timestamp management<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_session_start</span><span style="color: #007700">() {<br />    </span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br />    </span><span style="color: #FF8000">// Do not allow to use too old session ID<br />    </span><span style="color: #007700">if (!empty(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'deleted_time'</span><span style="color: #007700">]) &amp;&amp; </span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'deleted_time'</span><span style="color: #007700">] &lt; </span><span style="color: #0000BB">time</span><span style="color: #007700">() - </span><span style="color: #0000BB">180</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">session_destroy</span><span style="color: #007700">();<br />        </span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br />    }<br />}<br /><br /></span><span style="color: #FF8000">// My session regenerate id function<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">my_session_regenerate_id</span><span style="color: #007700">() {<br />    </span><span style="color: #FF8000">// Call session_create_id() while session is active to <br />    // make sure collision free.<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">session_status</span><span style="color: #007700">() != </span><span style="color: #0000BB">PHP_SESSION_ACTIVE</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br />    }<br />    </span><span style="color: #FF8000">// WARNING: Never use confidential strings for prefix!<br />    </span><span style="color: #0000BB">$newid </span><span style="color: #007700">= </span><span style="color: #0000BB">session_create_id</span><span style="color: #007700">(</span><span style="color: #DD0000">'myprefix-'</span><span style="color: #007700">);<br />    </span><span style="color: #FF8000">// Set deleted timestamp. Session data must not be deleted immediately for reasons.<br />    </span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">[</span><span style="color: #DD0000">'deleted_time'</span><span style="color: #007700">] = </span><span style="color: #0000BB">time</span><span style="color: #007700">();<br />    </span><span style="color: #FF8000">// Finish session<br />    </span><span style="color: #0000BB">session_commit</span><span style="color: #007700">();<br />    </span><span style="color: #FF8000">// Make sure to accept user defined session ID<br />    // NOTE: You must enable use_strict_mode for normal operations.<br />    </span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'session.use_strict_mode'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />    </span><span style="color: #FF8000">// Set new custom session ID<br />    </span><span style="color: #0000BB">session_id</span><span style="color: #007700">(</span><span style="color: #0000BB">$newid</span><span style="color: #007700">);<br />    </span><span style="color: #FF8000">// Start with custom session ID<br />    </span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br />}<br /><br /></span><span style="color: #FF8000">// Make sure use_strict_mode is enabled.<br />// use_strict_mode is mandatory for security reasons.<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'session.use_strict_mode'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">my_session_start</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Session ID must be regenerated when<br />//  - User logged in<br />//  - User logged out<br />//  - Certain period has passed<br /></span><span style="color: #0000BB">my_session_regenerate_id</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Write useful codes<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.session-create-id-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.session-regenerate-id.php" class="function" rel="rdfs-seeAlso">session_regenerate_id()</a> - Update the current session id with a newly generated one</span></li>
    <li><span class="function"><a href="function.session-start.php" class="function" rel="rdfs-seeAlso">session_start()</a> - Inizializza i dati di sessione</span></li>
    <li><a href="session.configuration.php#ini.session.use-strict-mode" class="link">session.use_strict_mode</a></li>
    <li><span class="methodname"><a href="sessionhandler.create-sid.php" class="methodname" rel="rdfs-seeAlso">SessionHandler::create_sid()</a> - Return a new session ID</span></li>
   </ul>
  </p>
 </div>

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