在我的網頁中,我有 2 個角色“用戶”和“管理員”。管理員有權創建、讀取、更新和洗掉。用戶可以訪問創建,但也可以在概覽表上查看記錄的短部分。
if ($_SESSION['userRole'] !== 'ADMIN') {
header("Location:index.php");
exit;
}
這是我在更改之前通常使用的,我想在edit.php中驗證角色。而且我也嘗試過允許用戶進行編輯。
if ($_SESSION['userRole'] !== 'ADMIN' or !== 'USER') {
header("Location:index.php");
exit;
}
//////////////////////////////////////////////////////////////
if ($_SESSION['userRole'] !== 'ADMIN' || !=='USER') {
header("Location:index.php");
exit;
}
//////////////////////////////////////////////////////////////
if ($_SESSION['userRole'] !== 'ADMIN') {
header("Location:index.php");
exit;
}elseif ($_SESSION['userRole'] !== 'USER') {
header("Location:index.php");
exit;
}
按下編輯按鈕時。該頁面不執行任何操作。這發生在管理員和用戶
uj5u.com熱心網友回復:
首先,我認為你應該使用整數而不是字串
$_SESSION["role"] = 666; //Admin
$_SESSION["role"] = 1; //User
在您的登錄中。
if($_SESSION["role"] === 666){
// redirect to the admin-page
}elseif($_SESSION["role"] === 1){
// redirect to users-page
}else{
//redirect your "both" page
}
嘗試檢查重定向頁面是否存在,如果不存在則拋出錯誤。
祝你好運
uj5u.com熱心網友回復:
試試這個來源,我認為錯誤將來自“標頭已發送”
if ($_SESSION['userRole'] !== 'ADMIN' OR $_SESSION['userRole'] !== 'USER') {
echo '<script> window.location.replace("https://www.example.com"); </script>';
die();
}
//////////////////////////////////////////////////////////////
if ($_SESSION['userRole'] !== 'ADMIN' || $_SESSION['userRole'] !=='USER') {
echo '<script> window.location.replace("https://www.example.com"); </script>';
die();
}
//////////////////////////////////////////////////////////////
if ($_SESSION['userRole'] !== 'ADMIN') {
echo '<script> window.location.replace("https://www.example.com"); </script>';
die();
}elseif ($_SESSION['userRole'] !== 'USER') {
echo '<script> window.location.replace("https://www.example.com"); </script>';
die();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/414302.html
標籤:
上一篇:按日期和其他識別符號拆分陣列
