Function name: session_destroy()
Function description: The session_destroy() function is used to destroy all data in the current session. It will delete all session variables and reset the session ID.
Applicable version: PHP 4, PHP 5, PHP 7
Usage: session_destroy(void): void
Example:
// 开启会话session_start(); // 设置会话变量$_SESSION['username'] = 'John'; // 销毁会话session_destroy(); // 输出会话变量echo $_SESSION['username'];
In the example above, we first start a session through the session_start() function and set a session variable $_SESSION['username'] with the value 'John'. Then, we call the session_destroy() function to destroy the session. Finally, we try to output $_SESSION['username'], but the variable will no longer be available because the session has been destroyed.
It should be noted that calling the session_destroy() function will only destroy the data in the current session and will not affect other sessions. If you want to terminate the session completely and delete all session data, you can use the session_unset() function to clear the session variables, and then call the session_destroy() function to destroy the session.