Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 6176

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>Get and/or set the current session name</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-module-name.html">session_module_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-regenerate-id.html">session_regenerate_id</a></div>
 <div class="up"><a href="ref.session.html">Session Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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)</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="type">string</span> <span class="methodname"><strong>session_name</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></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 class="emphasis">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 output content when <em>session.transid</em> is
   enabled). Once the HTTP cookie is
   sent, <span class="function"><strong>session_name()</strong></span> raises error.
   <span class="function"><strong>session_name()</strong></span> must be called
   before <span class="function"><a href="function.session-start.html" 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
   <em>session.name</em> 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.html" 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. <em>PHPSESSID</em>). 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, 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 class="emphasis">old</em> session
   is returned.
  </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-5962">
    <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">/*&nbsp;set&nbsp;the&nbsp;session&nbsp;name&nbsp;to&nbsp;WebsiteID&nbsp;*/<br /><br /></span><span style="color: #0000BB">$previous_name&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #DD0000">"The&nbsp;previous&nbsp;session&nbsp;name&nbsp;was&nbsp;</span><span style="color: #0000BB">$previous_name</span><span style="color: #DD0000">&lt;br&nbsp;/&gt;"</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.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>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.html" class="function">session_start()</a></span> which may crash PHP
        and may result in misbehaviors.
       </td>
      </tr>

     </tbody>
    
   </table>

  </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 class="member">
     The <a href="session.configuration.html#ini.session.name" class="link">session.name</a> configuration
     directive
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-module-name.html">session_module_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-regenerate-id.html">session_regenerate_id</a></div>
 <div class="up"><a href="ref.session.html">Session Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>