Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP---if(!session_)已注册不推荐?_Php - Fatal编程技术网

PHP---if(!session_)已注册不推荐?

PHP---if(!session_)已注册不推荐?,php,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语句已被弃用

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();
}
如果(!session_已注册('firstname')){
页眉(“location:index.php”);//页面上是否有session_start()


根据你的第一个片段,我认为你在逻辑上失败了

尝试:

if(!isset($\u会话['firstname'])){

header(“location:index.php”);//若要使用基于cookie的会话,必须在将任何内容输出到浏览器之前调用session_start()。如果
$\u session['firstname']
可能为null但已设置,请尝试
数组_key_exists('firstname',$\u session)
此外,在第一个示例中,如果变量不存在,则重定向;在第二个示例中,如果变量存在,则重定向。这是您的预期操作吗?
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();
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>');
}