session_destroy Destroys all data registered to a session php函数


(PHP 4, PHP 5)

session_destroyDestroys all data registered to a session


bool session_destroy ( void )

session_destroy() 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, session_start() has to be called.

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. setcookie() may be used for that.


成功时返回 TRUE, 或者在失败时返回 FALSE.


Example #1 Destroying a session with $_SESSION

// Initialize the session.
// If you are using session_name("something"), don't forget it now!

// 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.



Only use session_unset() for older deprecated code that does not use $_SESSION.


session_encode 将当前会话数据编码为一个字符串
session_get_cookie_params Get the session cookie parameters
session_id Get and/or set the current session id
session_is_registered 检查变量是否在会话中已经注册
session_module_name Get and/or set the current session module
session_name Get and/or set the current session name
session_regenerate_id Update the current session id with a newly generated one
session_register Register one or more global variables with the current session
session_save_path Get and/or set the current session save path
session_set_cookie_params Set the session cookie parameters
session_set_save_handler Sets user-level session storage functions
session_start Initialize session data
session_status Returns the current session status
session_unregister Unregister a global variable from the current session

Copyright © 2016 phpStudy |