<?php
session_start();
$_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();
?>
1条答案
按热度按时间9rnv2umw1#
当用户关闭一个标签页时,JavaScript可以用来检测它并向服务器发送一个 AJAX 请求,结束PHP会话。这是你如何完成的:
并创建
sessionDestroy.php
文件来销毁会话(完全销毁会话的最佳方法-即使浏览器未关闭)