How to check if user has the $AdminID to access page? $_SESSION['iroles'] is my discord roles
if (isset($_SESSION['user'])) {
} else {
header("location: login.php");
}
for ($x = 0; $x < sizeof($_SESSION['iroles']); $x ) {
$CheckID = $_SESSION['iroles'][$x];
if ($CheckID == $AdminID) {
$AdminID = "10084505484727420002";
$Access = true;
} else {
header("Location: error.php");
$Access = false;
}
}
CodePudding user response:
//User Role
$AdminID = "10084505484727420002";
//Roles stored in an array
$iroles = $_SESSION['iroles'];
//Checking for user access using in_array function
if (in_array($AdminID, $iroles)){
//Match found
$Access = true;
}else {
header("Location: error.php");
$Access = false;
}