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

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

问题描述

使用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();
}

什么原因导致此错误?

推荐答案

错误:

警告: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 )为 destroy 返回FALSE行动.这可以取决于您使用哪种类型的保存处理程序,默认的是文件.这样,当 session.save_path 设置错误(例如,不可访问的目录)时,会导致这种错误. /p>

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.

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

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