我想将管理员重定向到一个页面,并将其他用户重定向到另一个页面。 可以在 procedure 中执行,但不能在 oop 中执行。 管理员可能会添加新用户并显示他们有很多工作要做,而用户只能看到他/她的页面。
<?php
require_once('userClass.php');
$userObj = new USER();
session_start();
$type = $_GET['type'];
if(empty($type) || !isset($type)) {
echo 'Request type is not set';
} else if($type == 'signup') {
$data = USER::addNewUser($_REQUEST);
$_SESSION = $data;
if($data['status'] == 'error') {
header("location:register.php");
} else {
header("location:index.php");
}
} else if($type == 'login') {
$username = addslashes($_REQUEST['username']);
$password = addslashes($_REQUEST['password']);
$_SESSION = USER::login($username, $password);
if($_SESSION['status'] == 'error') {
header("location:index.php");
}
else {
header("location:profile.php");
}
/*if($_SESSION['username'] == 'admin@admin.com') {
header("location:admin.php");
}
else {
header("location:profile.php");
}*/
} else if($type == 'logout') {
unset($_SESSION);
session_destroy();
header("location:index.php");
}
?>
正在寻找解决方案......请帮忙。 *查看代码中的注释部分。
最佳答案
最简单的方法之一就是定义角色。
例如
if($_SESSION['username'] == 'admin@admin.com' && $_POST['role'] = 'admin'){
header("location:admin.php");
}
else {
header("location:profile.php");
}
关于php - 登录时重定向到不同页面 - php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47767830/