<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.session-name.php',
    1 => 'session_name',
    2 => 'Get and/or set the current session name',
  ),
  'up' => 
  array (
    0 => 'ref.session.php',
    1 => 'Session Functions',
  ),
  'prev' => 
  array (
    0 => 'function.session-module-name.php',
    1 => 'session_module_name',
  ),
  'next' => 
  array (
    0 => 'function.session-regenerate-id.php',
    1 => 'session_regenerate_id',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/session/functions/session-name.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.session-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_name</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">session_name</span> &mdash; <span class="dc-title">Get and/or set the current session name</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.session-name-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>session_name</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$name</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></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_name()</strong></span> returns the name of the current
   session. If <code class="parameter">name</code> is given,
   <span class="function"><strong>session_name()</strong></span> will update the session name and return
   the <em>old</em> session name.
  </p>
  <p class="para">
   If a new session <code class="parameter">name</code> is
   supplied, <span class="function"><strong>session_name()</strong></span> modifies the HTTP cookie
   (and outputs the content when <a href="session.configuration.php#ini.session.use-trans-sid" class="link">session.use_trans_sid</a> is
   enabled). Once the HTTP cookie has been
   sent, calling <span class="function"><strong>session_name()</strong></span> raises an <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
   <span class="function"><strong>session_name()</strong></span> must be called
   before <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> for the session to work
   properly.
  </p>
  <p class="para">
   The session name is reset to the default value stored in
   <code class="literal">session.name</code> at request startup time. Thus, you need to
   call <span class="function"><strong>session_name()</strong></span> for every request (and before
   <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> is called).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.session-name-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       The session name references the name of the session, which is 
       used in cookies and URLs (e.g. <code class="literal">PHPSESSID</code>). It
       should contain only alphanumeric characters; it should be short and
       descriptive (i.e. for users with enabled cookie warnings).
       If <code class="parameter">name</code> is specified and not <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, the name of the current
       session is changed to its value.
      </p>
      <p class="para">
       <div class="warning"><strong class="warning">Warning</strong>
        <p class="para">
         The session name can&#039;t consist of digits only, at least one letter
         must be present. Otherwise a new session id is generated every time.
        </p>
       </div>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-name-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the name of the current session. If <code class="parameter">name</code> is given
   and function updates the session name, name of the <em>old</em> session
   is returned,  or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.session-name-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>8.0.0</td>
       <td>
        <code class="parameter">name</code> is nullable now.
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        <span class="function"><strong>session_name()</strong></span> checks session status,
        previously it only checked cookie status. Therefore,
        older <span class="function"><strong>session_name()</strong></span> allows to
        call <span class="function"><strong>session_name()</strong></span>
        after <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> which may crash PHP
        and may result in misbehaviors.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.session-name-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>session_name()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/* set the session name to WebsiteID */<br /><br /></span><span style="color: #0000BB">$previous_name </span><span style="color: #007700">= </span><span style="color: #0000BB">session_name</span><span style="color: #007700">(</span><span style="color: #DD0000">"WebsiteID"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"The previous session name was </span><span style="color: #0000BB">$previous_name</span><span style="color: #DD0000">&lt;br /&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.session-name-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li>
     The <a href="session.configuration.php#ini.session.name" class="link">session.name</a> configuration
     directive
    </li>
   </ul>
  </p>
 </div>


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