Source of: /manual/en/function.session-destroy.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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-destroy.php',
1 => 'session_destroy',
),
'up' =>
array (
0 => 'ref.session.php',
1 => 'Session Functions',
),
'prev' =>
array (
0 => 'function.session-decode.php',
1 => 'session_decode',
),
'next' =>
array (
0 => 'function.session-encode.php',
1 => 'session_encode',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.session-destroy" class="refentry">
<div class="refnamediv">
<h1 class="refname">session_destroy</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">session_destroy</span> — <span class="dc-title">Destroys all data registered to a session</span></p>
</div>
<a name="function.session-destroy.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>session_destroy</b></span>
( <span class="methodparam">void</span>
)</div>
<p class="simpara">
<b>session_destroy()</b> destroys all of the data associated
with the current session. It does not unset any of the global variables
associated with the session, or unset the session cookie.
To use the session variables again, <a href="function.session-start.php" class="function">session_start()</a> has
to be called.
</p>
<p class="para">
In order to kill the session altogether, like to log the user out, the
session id must also be unset. If a cookie is used to propagate the
session id (default behavior), then the session cookie must be deleted.
<a href="function.setcookie.php" class="function">setcookie()</a> may be used for that.
</p>
</div>
<a name="function.session-destroy.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.session-destroy.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Destroying a session with <var class="varname"><a href="reserved.variables.session.php" class="classname">$_SESSION</a></var></b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Initialize the session.<br />// If you are using session_name("something"), don't forget it now!<br /></span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Unset all of the session variables.<br /></span><span style="color: #0000BB">$_SESSION </span><span style="color: #007700">= array();<br /><br /></span><span style="color: #FF8000">// If it's desired to kill the session, also delete the session cookie.<br />// Note: This will destroy the session, and not just the session data!<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">"session.use_cookies"</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$params </span><span style="color: #007700">= </span><span style="color: #0000BB">session_get_cookie_params</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #0000BB">session_name</span><span style="color: #007700">(), </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #0000BB">time</span><span style="color: #007700">() - </span><span style="color: #0000BB">42000</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"path"</span><span style="color: #007700">], </span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"domain"</span><span style="color: #007700">],<br /> </span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"secure"</span><span style="color: #007700">], </span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"httponly"</span><span style="color: #007700">]<br /> );<br />}<br /><br /></span><span style="color: #FF8000">// Finally, destroy the session.<br /></span><span style="color: #0000BB">session_destroy</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.session-destroy.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<blockquote><p><b class="note">Note</b>:
Only use <a href="function.session-unset.php" class="function">session_unset()</a> for older deprecated code
that does not use <var class="varname"><a href="reserved.variables.session.php" class="classname">$_SESSION</a></var>.
<br />
</p></blockquote>
</div>
<a name="function.session-destroy.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.unset.php" class="function" rel="rdfs-seeAlso">unset()</a> - Unset a given variable</li>
<li class="member"><a href="function.setcookie.php" class="function" rel="rdfs-seeAlso">setcookie()</a> - Send a cookie</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>