📄 function.session-destroy.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Destroys all data registered to a session</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.session-decode.html">session_decode</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-encode.html">session_encode</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-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> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>session_destroy</b></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. </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.html" class="function">setcookie()</a> may be used for that. </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <b><tt>TRUE</tt></b> on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Destroying a session with <var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION</a></var></b></p> <div class="example-contents"><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 (isset(</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">[</span><span style="color: #0000BB">session_name</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">, </span><span style="color: #DD0000">'/'</span><span style="color: #007700">);<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> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: Only use <a href="function.session-unset.html" class="function">session_unset()</a> for older deprecated code that does not use <var class="varname"><a href="reserved.variables.session.html" class="classname">$_SESSION</a></var>. <br /> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.unset.html" class="function" rel="rdfs-seeAlso">unset()</a></li> <li class="member"><a href="function.setcookie.html" class="function" rel="rdfs-seeAlso">setcookie()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.session-decode.html">session_decode</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.session-encode.html">session_encode</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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -