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 關注
- 243 瀏覽
添加回答
舉報