PHP --- if(!session_is_registered已弃用?

时间:2011-09-25 06:16:04

标签: php

此if语句已被弃用

if(!session_is_registered('firstname')){ 
header("location: index.php"); // << makes the script send them to any page we set
} else {
print "<h2>Could not log you out, sorry the system encountered an error.</h2>";
exit();
}

我用

替换了它
if ( isset( $_SESSION['firstname'] ) ){
header("location: index.php"); // << makes the script send them to any page we set
} else {
print "<h2>Could not log you out, sorry the system encountered an error.</h2>";
exit();

初始代码附加到我的logout.php脚本中。当我转到链接logout.php时,会显示“无法将您注销,抱歉系统遇到错误。”

这是正确的解决方案,因为我对代码没有问题

2 个答案:

答案 0 :(得分:1)

根据您的第一个片段,我认为您的逻辑失败。

尝试:

if ( !isset($_SESSION['firstname']) ){
    header("location: index.php"); // << makes the script send them to any page we set
} else {
    exit('<h2>Could not log you out, sorry the system encountered an error.</h2>');
}

答案 1 :(得分:0)

你有session_start();在你的页面上?

http://php.net/manual/en/function.session-start.php