我有一个网站试图添加登录系统,一切顺利,除了admin / index.php上的会话
这里是常规会话页保护,适用于保护页面但无法控制用户级别的所有类型的用户
session_start();
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
header("location: login.php");
exit;
}
这是管理员用户的会话控制。我试过。
if(!isset($_SESSION['username']['ifadmin'] == '1' || empty($_SESSION['username']['if admin'] == '1')){
header("location: login.php");
exit;
}
普通用户 的index.php
if(!isset($_SESSION['username']['ifadmin'] == '2' || empty($_SESSION['username']['if admin'] == '2')){
header("location: login.php");
exit;
}
这是我遇到的错误
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in D:\wamp\www\site\index.php on line 5
我的会议工作变量
if(!isset($_SESSION['username']) || $_SESSION['ifadmin']!=1){
header('Location: login.php');
exit();
}
如何检查emty现在?
答案 0 :(得分:0)
你可以试试这个:
if(isset($_SESSION['user_id']=='1') && $_SESSION['user_id'] != '')
{
header("location: login.php");
}
else if(isset($_SESSION['admin_id']=='2') && $_SESSION['admin_id'] != '')
{
header("location: login.php");
}