首页 >函数列表 >session_destroy

session_destroy

session_destroy

(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

<?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();
?>

注释

Note:

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

参见


  • session_cache_expire
  • session_cache_limiter
  • session_commit
  • session_decode
  • session_destroy
  • session_encode
  • session_get_cookie_params
  • session_id
  • session_is_registered
  • session_module_name
  • session_name
  • session_regenerate_id
  • session_register
  • session_save_path
  • session_set_cookie_params
  • session_set_save_handler
  • session_start
  • session_status
  • session_unregister
  • session_unset
  • session_write_close
  • PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道