Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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
注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的管理员注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的用户_Php - Fatal编程技术网

注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的管理员注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的用户

注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的管理员注意:未定义索引:C:\xampp\htdocs\deped2\index.php中的用户,php,Php,这是我的密码 <?php include("include/dbcon.php"); if($_SESSION['admin']){ //this is where the error starts header("location:admin/"); }else if($_SESSION['users']){ //and here also header('location:employee/'); }else{ header:('location

这是我的密码

<?php

include("include/dbcon.php");
if($_SESSION['admin']){      //this is where the error starts
    header("location:admin/");
}else if($_SESSION['users']){   //and here also
    header('location:employee/');
}else{
    header:('location:/deped2/');
}
?>

请帮我处理此代码

您没有检查会话索引是否已设置。最好先启动会话,然后检查变量是否存在

尝试此操作并添加退出;在每个标题之后。否则,您的代码可能希望继续执行

<?php

if(!isset($_SESSION)){
session_start();
}
include("include/dbcon.php");
if(isset($_SESSION['admin'])){      //this is where the error starts
    header("location:admin/");
    exit;
}else if(isset($_SESSION['users'])){   //and here also
    header('location:employee/');
    exit;
}else{
    header:('location:/deped2/');
    exit;
}

?>

chk会话,你是否开始了会话除了当前的答案可以解决你的问题外,我建议使用exit;在每个标题“Location:…”之后。我将把include放在条件下面。如果失败,那么它将抛出headers sent警告并添加exit;在每一个标题后面都有一个更好的答案。是的,你可以把include放在条件后面。