I'm trying to restrict users from accessing a page if their rank isn't manager or admin. I made a variable called $rank which is the rank that is fetched from the user's table in my database. When I echo the rank on the page, the rank does equal to manager or admin but it redirects me to the index page because it somehow doesn't equal manager or admin. When I try using this code:
if(!isset($_SESSION['userID'])) {
header("Location: index.php");
} else if ($rank == "manager" OR $rank == "admin") {
} else {
header("Location: index.php");
}
it does work but I feel like that's the wrong way of doing it. This is the code that I'm using now and isn't working:
$tUsers_Select = "SELECT users.rank, ranks.rank_name FROM users LEFT JOIN ranks ON users.rank = ranks.rank_name WHERE user_id = ".$_SESSION['userID'];
$tUsers_Select_Query = mysqli_query($dbConnect, $tUsers_Select);
$fetch = mysqli_fetch_array($tUsers_Select_Query);
$rank = $fetch['rank'];
if(!isset($_SESSION['userID'])) {
header("Location: index.php");
} else if ($rank !== "manager" OR $rank !== "admin") {
header("Location: index.php");
}
Hopefully you understood. Please comment if you have any questions.