简体   繁体   English

警告:session_destroy()?

[英]Warning: session_destroy()?

Im trying to fix my login script, on my localhost it works but uploaded to my online test server, the logout is broken, I get this error: 我试图修复我的登录脚本,在我的localhost它工作但上传到我的在线测试服务器,注销被破坏,我收到此错误:

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in htdocs/logout.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at htdocs/logout.php:17) in htdocs/logout.php on line 18

Warning: Cannot modify header information - headers already sent by (output started at htdocs/logout.php:17) in www/htdocs/logout.php on line 34

Not quite sure what could be causing it since it was working on my localhost, any ideas? 不太确定是什么导致它,因为它正在我的本地主机上工作,任何想法?

session_start();
session_destroy(); /*or sesion_unset();*/

要使session_destroy工作,必须使用session_start启动会话。

If you need to just delete the session if it exists (for example in an auto called exit/logout/destructor script) and it may or may not exist, then you can use session_status to check the status. 如果您只需要删除会话(例如在自动调用的exit / logout /析构函数脚本中)并且它可能存在也可能不存在,那么您可以使用session_status来检查状态。

As of PHP 5.4.0, you can check it like this: 从PHP 5.4.0开始,您可以这样检查:

if(session_status() == PHP_SESSION_ACTIVE)
{
    session_destroy();
}

This is preferable to creating a new section just to destroy it later. 这比创建一个新的部分只是为了以后销毁它更好。

Per the PHP manual, session_status will return an integer that can be compared with the following constants: 根据PHP手册,session_status将返回一个可与以下常量进行比较的整数:

Return Values 

• PHP_SESSION_DISABLED - Returned if sessions are disabled. 
• PHP_SESSION_NONE - Returned if sessions are enabled, but none exists. 
• PHP_SESSION_ACTIVE - Returned if sessions are enabled, and one exists. 

This allows you to write better, more efficient, and more flexible session management code. 这使您可以编写更好,更高效,更灵活的会话管理代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM