philip          Tue Aug 31 20:31:32 2004 EDT

  Modified files:              
    /phpdoc/en/reference/session/functions      session-destroy.xml 
  Log:
  Implemented info/example about deleting the session id cookie.  Removed deprecated
  use of session_unset() and wrote it as a note instead.  Implemented return.success,
  and added see also.
  
  
http://cvs.php.net/diff.php/phpdoc/en/reference/session/functions/session-destroy.xml?r1=1.2&r2=1.3&ty=u
Index: phpdoc/en/reference/session/functions/session-destroy.xml
diff -u phpdoc/en/reference/session/functions/session-destroy.xml:1.2 
phpdoc/en/reference/session/functions/session-destroy.xml:1.3
--- phpdoc/en/reference/session/functions/session-destroy.xml:1.2       Wed Apr 17 
02:43:58 2002
+++ phpdoc/en/reference/session/functions/session-destroy.xml   Tue Aug 31 20:31:31 
2004
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
 <!-- splitted from ./en/functions/session.xml, last change in rev 1.2 -->
   <refentry id="function.session-destroy">
    <refnamediv>
@@ -18,50 +18,51 @@
      the global variables associated with the session, or unset the
      session cookie.
     </simpara>
+    <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 propogate the 
+     session id (default behavior), then the session cookie must be deleted.  
+     <function>setcookie</function> may be used for that.
+    </para>
     <simpara>
-     This function returns &true; on success and 
-     &false; on failure to destroy
-     the session data.
+     &return.success;
     </simpara>
     <para>
      <example>
-      <title>Destroying a session</title>
+      <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_unset();
-// Finally, destroy the session.
-session_destroy();
 
-?>
-]]>
-      </programlisting>
-     </example>
-    </para>
-    <para>
-     <example>
-      <title>Destroying a session with $_SESSION</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 (isset($_COOKIE[session_name()])) {
+    setcookie(session_name(), '', time()-42000, '/');
+}
+
 // Finally, destroy the session.
 session_destroy();
-
 ?>
 ]]>
       </programlisting>
      </example>
+    </para>
+    <note>
+     <para>
+      Only use <function>session_unset</function> for older deprecated code 
+      that does not use <varname>$_SESSION</varname>.
+     </para>
+    </note>
+    <para>
+     See also
+     <function>unset</function> and
+     <function>setcookie</function>.
     </para>
    </refsect1>
   </refentry>

Reply via email to