<!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 id</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.session-get-cookie-params.html">session_get_cookie_params</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-is-registered.html">session_is_registered</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-id" class="refentry"> <div class="refnamediv"> <h1 class="refname">session_id</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">session_id</span> — <span class="dc-title">Get and/or set the current session id</span></p> </div> <div class="refsect1 description" id="refsect1-function.session-id-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>session_id</strong></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$id</code></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>session_id()</strong></span> is used to get or set the session id for the current session. </p> <p class="para"> The constant <strong><code>SID</code></strong> can also be used to retrieve the current name and session id as a string suitable for adding to URLs. See also <a href="ref.session.html" class="link">Session handling</a>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.session-id-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">id</code></em></span> <dd> <p class="para"> If <em><code class="parameter">id</code></em> is specified, it will replace the current session id. <span class="function"><strong>session_id()</strong></span> needs to be called before <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> for that purpose. Depending on the session handler, not all characters are allowed within the session id. For example, the file session handler only allows characters in the range <em>a-z A-Z 0-9 , (comma) and - (minus)</em>! </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> When using session cookies, specifying an <em><code class="parameter">id</code></em> for <span class="function"><strong>session_id()</strong></span> will always send a new cookie when <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> is called, regardless if the current session id is identical to the one being set. </span> </p></blockquote> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.session-id-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <span class="function"><strong>session_id()</strong></span> returns the session id for the current session or the empty string (<em>""</em>) if there is no current session (no current session id exists). </p> </div> <div class="refsect1 changelog" id="refsect1-function.session-id-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>,</em> (comma) and <em>-</em> (minus) characters are allowed in the file session handler. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-function.session-id-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.session-regenerate-id.html" class="function" rel="rdfs-seeAlso">session_regenerate_id()</a> - Update the current session id with a newly generated one</span></li> <li class="member"> <span class="function"><a href="function.session-start.html" class="function" rel="rdfs-seeAlso">session_start()</a> - Start new or resume existing session</span></li> <li class="member"> <span class="function"><a href="function.session-set-save-handler.html" class="function" rel="rdfs-seeAlso">session_set_save_handler()</a> - Sets user-level session storage functions</span></li> <li class="member"> <a href="session.configuration.html#ini.session.save-handler" class="link">session.save_handler</a> </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-get-cookie-params.html">session_get_cookie_params</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-is-registered.html">session_is_registered</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>