<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.session-destroy">
 <refnamediv>
  <refname>session_destroy</refname>
  <refpurpose>Destroys all data registered to a session</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>session_destroy</methodname>
   <void/>
  </methodsynopsis>
  <simpara>
   <function>session_destroy</function> 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, <function>session_start</function> has
   to be called.
  </simpara>
  <note>
   <simpara>
     You do not have to call <function>session_destroy</function> from usual
     code. Cleanup $_SESSION array rather than destroying session data.
   </simpara>
  </note>
  <para>
   In order to kill the session altogether, 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.
   <function>setcookie</function> may be used for that.
  </para>
  <para>
   When <link linkend="ini.session.use-strict-mode">session.use_strict_mode</link>
   is enabled. You do not have to remove obsolete session ID cookie because
   session module will not accept session ID cookie when there is no
   data associated to the session ID and set new session ID cookie.
   Enabling <link linkend="ini.session.use-strict-mode">session.use_strict_mode</link>
   is recommended for all sites.
  </para>
  <warning>
   <para>
    Immediate session deletion may cause unwanted results. When there is
    concurrent requests, other connections may see sudden session data
    loss. e.g. Requests from JavaScript and/or requests from URL links.
   </para>
   <para>
    Although current session module does not accept empty session ID
    cookie, but immediate session deletion may result in empty session ID
    cookie due to client(browser) side race condition. This will result
    that the client creates many session ID needlessly.
   </para>
   <para>
    To avoid these, you must set deletion time-stamp to $_SESSION and
    reject access while later. Or make sure your application does not
    have concurrent requests. This applies to <function>session_regenerate_id</function> also.
   </para>
  </warning>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  &no.function.parameters;
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Destroying a session with <varname>$_SESSION</varname></title>
    <programlisting role="php">
<![CDATA[
<?php
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><link linkend="ini.session.use-strict-mode">session.use_strict_mode</link></member>
    <member><function>session_reset</function></member>
    <member><function>session_regenerate_id</function></member>
    <member><function>unset</function></member>
    <member><function>setcookie</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
