3 回答

TA贡献1845条经验 获得超8个赞
例如,给他们特定的角色(admin,srudent),登录后,做这样的事情
$role = 从你的数据库中获取角色;
if(role == 'admin'){ 然后重定向管理面板}
elseif(role=='student'){重定向到学生位置}
else{重定向到另一个地方}

TA贡献1789条经验 获得超10个赞
这对我有用。谢谢你的帮助...
<?php if (isset($conn,$_POST['login'])) {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);
$sql = "SELECT * FROM staff WHERE Domain = '$username'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
if(password_verify($password, $row["Pass"]))
{
//return true;
$_SESSION["username"] = $username;
$role=$row['Role'];
if($role == 'Admin'){
header("location: dashboard.php");
}
elseif($role=='Staff'){
header("location: index.php");
}
else{
header("location: login.php");
}
}
else {
//return false;
echo '<script>alert("Wrong User Password")</script>';
}
}
}
else
{
echo '<script>alert("Sorry! No such User Name is found")</script>';
}
}
?>

TA贡献1876条经验 获得超7个赞
1.) 首先在数据库表字段中添加用户类型,您的数据库表结构如下:-
table:-
id username password Role
1 --- ---- admin
2 --- ---- Student
3 ---- ---- Teacher
我认为你的问题是检查条件,使用 if 和 else 语句。
$_SESSION['username'] = $name[0];
$_SESSION['password'] = $name[1];
$_SESSION['Role'] = $name[2];
if($_SESSION['Role'] == 'admin'){
header("Location: admin.php");
}
else if($_SESSION['Role'] == 'Student'){
header("Location: Student.php");
}
else if($_SESSION['Role'] == 'Teacher'){
header("Location: Teacher.php");
}
else{
echo "Your not logged in";
}
希望对你有帮助......
- 3 回答
- 0 关注
- 210 浏览
添加回答
举报