销毁 PHP 会话 [英] Destroying PHP Session

查看:50
本文介绍了销毁 PHP 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stackoverflow 上有很多关于销毁会话的页面.相信我,我一直在阅读它们,我遇到了这个:为什么我的会话仍然存在?

There are lots of pages on stackoverflow about destorying session. Trust me, I have been reading them all and I came across this: Why does my session remain?

我的问题很简单,我真的需要执行以下所有操作才能正确销毁会话吗?

My question is simple, is it really true that I need to do all of the below just to properly destroy a session?

$tmp = session_id();
session_destroy();
session_id($tmp);
unset($tmp);

这是唯一一个建议采取此类极端措施的页面.大多数页面只是建议 session_destroy();.

This is the only page that suggests such extreme measures. Most pages just suggest session_destroy();.

只是为了澄清,因为似乎有些混乱,我正在寻找最有效的方法.

Just to clarify because there seems to be some confusion I am looking for the most efficent method that is effective.

提前致谢.

推荐答案

新的答案已经停止出现,所以我把我根据所有答案学到的东西放进去.这是各种答案的汇总.希望它会帮助其他人.下面列出了销毁会话 100% 有效的最有效方法:

New answers have stopped coming in so I am putting in what I learnt based on all of the answers. This is an aggregation of the various answers. Hopefully it will help others. The most efficient method that is 100% effective for destroying a session is listed below:

if (ini_get("session.use_cookies")) 
{
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
        );
}

$_SESSION = array();
$tmp = session_id();
session_id($tmp);
unset($tmp);
session_unset();
session_destroy();
session_write_close();
session_regenerate_id(True); // true indicates the need to delete the old session

感谢大家的帮助,向我展示了如何做到这一点.这不是一个人的努力.我要特别感谢@Kerrek SB、@Uday @Dhruvisha.如果您有更多建议,请随时添加评论,我会编辑我的答案.

Thanks to everyone for their help showing me how to do this. This was not a single person effort. I would particularly like to thank @Kerrek SB, @Uday @Dhruvisha. If you have more suggests please feel free to add comments and I will edit my answer.

这篇关于销毁 PHP 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆