[英]I have two types of users - User and Admin. I would like to include a session check, to check if the person is logging on as a user or as an admin.
这是我包含的代码:
<?php
session_start();
if(!isset($_SESSION['userid']) OR $_SESSION['userid']==''){
header('Location: Loginhome.php');
}
elseif(isset($_SESSION['user_type']) && $_SESSION['user_type'] =='Admin'){
header('Location: adminhome.php');
}
else{
header('Location: userhome.php');
exit;
}
?>
并且此代码表示登录后页面未正确重定向。
<?php
session_start();
if(!isset($_SESSION['user_type']=='1']) OR $_SESSION['userid']==''){
header('Location: Loginhome.php');
}
else
if(isset($_SESSION['user_type']=='2']) && $_SESSION['user_type'] =='Admin'){
header('Location: adminhome.php');
}
else{
header('Location: userhome.php');
exit;
}
?>
你需要做这样的事情
你需要帮助这个
声明一个角色
//对于管理员
如果($_SESSION['user']['role'] == 1){
//你的代码在这里
}
//对于所有用户
if ($_SESSION['user']['role'] == 2 && $_SESSION['user']['name'] == $username) {
//你的代码在这里
}
祝大家好运
<?php
session_start();
if ($_SESSION['role'] !== 'admin') {
header('Location: ../index');
<?php
require_once('config.php');
require_once('classes/admin.class.php');
require_once('classes/log.class.php');
$OBJ_LOGIN = 新管理员();
$OBJ_LOG = 新日志();
//print_r($_SESSION);
if($OBJ_LOGIN->LoggedUser())
{
重定向('dashboard.php');
}
//$res_login = array();
$flg=0;
$action = $_GET['a'];
if($action == '注销')
{
// $sql1 = "INSERT INTO log VALUES(NULL,'".$_SESSION['userempname']."','退出系统',NOW())";
$OBJ_LOG->userName = $_SESSION['userfullname'];
$OBJ_LOG->logText = '退出系统';
$res_log = $OBJ_LOG->Addlog();
// mysql_query($sql1);
如果(会话销毁())
{
重定向('index.php');
}
}
if($_POST['logfrm'] == 'yes')
{
$OBJ_LOGIN->aUsername = $_POST['uname'];
$OBJ_LOGIN->aPassword = md5($_POST['upwd']);
$res_login = $OBJ_LOGIN->LoginUser();
//print_r($res_login);
if($_POST['uname'] == $res_login[0]['aUsername'] && md5($_POST['upwd']) == $res_login[0]['aPassword'])
{
$_SESSION['adminid'] = $res_login[0]['adminID'];
$_SESSION['userrole'] = $res_login[0]['aType'];
$_SESSION['useremail'] = $res_login[0]['aEmail'];
$_SESSION['login_user'] = $res_login[0]['aUsername'];
$_SESSION['userpass'] = $res_login[0]['aPassword'];
$_SESSION['userfullname'] = $res_login[0]['aFullname'];
$_SESSION['userimg'] = $res_login[0]['aImage'];
$OBJ_LOG->userName = $_SESSION['userfullname'];
$OBJ_LOG->logText = '登录系统';
$log = $OBJ_LOG->Addlog();
重定向('dashboard.php');
}
别的
{
$flg = 1;
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.