PHP - 关闭浏览器后会话销毁 [英] PHP - Session destroy after closing browser
问题描述
虽然这个问题有多个重复,但我找不到适合我的解决方案.需要一些帮助.
Though this question has multiple duplicates i could not find proper solution for me. Need Some help.
我在我的配置文件中使用了 ini_set('session.cookie_lifetime', 0);
.
I have used ini_set('session.cookie_lifetime', 0);
in my configuration file.
但这并不能帮助我在浏览器关闭时销毁会话.
But it is not helping me to destroy session on browser close.
应用电流:
1) 在身份验证页面,如果用户有效,使用 session_regenerate_id(true);
1) In authentication page if user is valid, generate new session identifier using session_regenerate_id(true);
2) 控制转到welcome.php,在那里我使用session_start();
2) Control goes to welcome.php where i start new session using session_start();
3) 在登出页面代码是
3) in logout page code is
$_SESSION = array();
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();
推荐答案
关闭会话的最佳方式是:如果在特定时间间隔后该会话没有响应.然后关闭.请看这篇文章,我希望它能解决问题."如何在 PHP 中更改会话超时时间?"
The best way is to close the session is: if there is no response for that session after particular interval of time. then close. Please see this post and I hope it will resolve the issue. "How to change the session timeout in PHP?"
这篇关于PHP - 关闭浏览器后会话销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!