downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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> &mdash; <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">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;session.<br />//&nbsp;If&nbsp;you&nbsp;are&nbsp;using&nbsp;session_name("something"),&nbsp;don't&nbsp;forget&nbsp;it&nbsp;now!<br /></span><span style="color: #0000BB">session_start</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;Unset&nbsp;all&nbsp;of&nbsp;the&nbsp;session&nbsp;variables.<br /></span><span style="color: #0000BB">$_SESSION&nbsp;</span><span style="color: #007700">=&nbsp;array();<br /><br /></span><span style="color: #FF8000">//&nbsp;If&nbsp;it's&nbsp;desired&nbsp;to&nbsp;kill&nbsp;the&nbsp;session,&nbsp;also&nbsp;delete&nbsp;the&nbsp;session&nbsp;cookie.<br />//&nbsp;Note:&nbsp;This&nbsp;will&nbsp;destroy&nbsp;the&nbsp;session,&nbsp;and&nbsp;not&nbsp;just&nbsp;the&nbsp;session&nbsp;data!<br /></span><span style="color: #007700">if&nbsp;(</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">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">session_get_cookie_params</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #0000BB">session_name</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()&nbsp;-&nbsp;</span><span style="color: #0000BB">42000</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"path"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"domain"</span><span style="color: #007700">],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"secure"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">"httponly"</span><span style="color: #007700">]<br />&nbsp;&nbsp;&nbsp;&nbsp;);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Finally,&nbsp;destroy&nbsp;the&nbsp;session.<br /></span><span style="color: #0000BB">session_destroy</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites