【发布时间】:2018-01-05 15:33:43
【问题描述】:
如何根据角色重定向两个用户?我有数据库用户类型 1 和类型 0。我的登录代码是这样的。类型 1 假设是管理员,类型 0 是普通用户。
<?php
session_start();
if(isset($_POST['submit'])){
include 'dbh.inc.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
if (empty($uid) || empty($pwd)){
header("Location: ../index.php?login=empty");
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 1) {
header("Location: ../index.php?login=error");
exit();
} else {
if ($row = mysqli_fetch_assoc($result)){
$hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
if($hashedPwdCheck == false){
header("Location: ../index.php?login=error");
exit();
} elseif ($hashedPwdCheck == true) {
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../main.php?login=success");
exit();
}
}
}
}
} else {
header("Location: ../index.php?login=error");
exit();
}
【问题讨论】:
-
对于用户类型 1 和类型 0 ,创建一个 if else 标头条件,例如 header("Location: ../main.php?login=success"); to if(type==1){ header("位置:../main.php?login=success");}elseif(type==0){ header("位置:../mainuser.php?login=成功");}
-
那么您是否打算将管理员重定向到一个页面并将普通用户重定向到另一个页面?
-
是存储在 users 表中的用户类型。我没有看到这个字段?
-
是什么阻止我进入 main.php 并绕过身份验证?
-
是的管理员有不同的页面,用户有另一个页面,我有两个用户类型 1 和类型 0.....请编辑我的代码,我真的不知道如何编码我只是从网上复制粘贴过来的。