为什么Session对象销毁失败 [英] Why Session object destruction failed

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

问题描述

当我使用 session_destroy() 时,我收到会话对象销毁失败".

I get "Session object destruction failed" when I use session_destroy().

session_start();
if(isset($_SESSION['user_id'])){    
    $_SESSION=array();
    if(isset($_COOKIE[session_name()])){
        setcookie(session_name(),'',0,"/");
    }
    session_destroy();
}

是什么导致了这个错误?

What causes this error?

推荐答案

错误:

警告:session_destroy():会话对象销毁失败

Warning: session_destroy(): Session object destruction failed

很简单,没有会话已经启动对象已经提交,所以你不能销毁它.

It's rather trivial, no session has been started object has been comitted, so you can't destroy it.

@ 运算符并不总是处于活动状态,例如具有错误报告功能.

The @ operator is not always active, e.g. with error reporting functions.

1) 导致此错误的原因是什么?

1) What causes this error?

这个错误通常是因为PHP试图删除会话文件,但找不到它.

This error is normally caused when PHP tries to delete the session file, but it can't find it.

在您使用 session_destroy 的情况下,只有 PHP 中的一个地方 导致了这种情况.那时 session.save_handler(另见session_set_save_handler)返回FALSE 表示 destroy 动作.这取决于您使用哪种类型的保存处理程序,默认为 files.有了那个,当 session.save_path 设置错误(例如不是可访问的目录)时,这会导致这样的错误.

In your case with session_destroy there is only one place in PHP which causes this. That's when the session.save_handler (see as well session_set_save_handler) returns FALSE for the destroy action. This can depends which type of save-handler you use, the default one is files. With that one, when the session.save_path setting is wrong (e.g. not an accessible directory), this would cause such an error.

2) 为什么@"不会抑制错误?

2) Why would the "@" not be suppressing the error?

这取决于输出的创建方式和 PHP 配置.@ 并不总是有效.例如,使用 set_error_handler 注册的回调仍会收到这些消息.

That depends how the output is created and on PHP configuration. @ does not always work. For example callbacks registered with set_error_handler will still receive these messages.

这篇关于为什么Session对象销毁失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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