<!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>Update the current session id with a newly generated one</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.session-name.html">session_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-register-shutdown.html">session_register_shutdown</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-regenerate-id" class="refentry"> <div class="refnamediv"> <h1 class="refname">session_regenerate_id</h1> <p class="verinfo">(PHP 4 >= 4.3.2, PHP 5)</p><p class="refpurpose"><span class="refname">session_regenerate_id</span> — <span class="dc-title"> Update the current session id with a newly generated one </span></p> </div> <div class="refsect1 description" id="refsect1-function.session-regenerate-id-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>session_regenerate_id</strong></span> ([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$delete_old_session</code><span class="initializer"> = false</span></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>session_regenerate_id()</strong></span> will replace the current session id with a new one, and keep the current session information. </p> </div> <div class="refsect1 parameters" id="refsect1-function.session-regenerate-id-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">delete_old_session</code></em></span> <dd> <p class="para"> Whether to delete the old associated session file or not. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.session-regenerate-id-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 changelog" id="refsect1-function.session-regenerate-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>4.3.3</td> <td> Since then, if session cookies are enabled, use of <span class="function"><strong>session_regenerate_id()</strong></span> will also submit a new session cookie with the new session id. </td> </tr> <tr> <td>5.1.0</td> <td> Added the <em><code class="parameter">delete_old_session</code></em> parameter. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.session-regenerate-id-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4769"> <p><strong>Example #1 A <span class="function"><strong>session_regenerate_id()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />session_start</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$old_sessionid </span><span style="color: #007700">= </span><span style="color: #0000BB">session_id</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">session_regenerate_id</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$new_sessionid </span><span style="color: #007700">= </span><span style="color: #0000BB">session_id</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #DD0000">"Old Session: </span><span style="color: #0000BB">$old_sessionid</span><span style="color: #DD0000"><br />"</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">"New Session: </span><span style="color: #0000BB">$new_sessionid</span><span style="color: #DD0000"><br />"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$_SESSION</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.session-regenerate-id-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.session-id.html" class="function" rel="rdfs-seeAlso">session_id()</a> - Get and/or set the current session id</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-name.html" class="function" rel="rdfs-seeAlso">session_name()</a> - Get and/or set the current session name</span></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-name.html">session_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-register-shutdown.html">session_register_shutdown</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>