简体   繁体   English

如何检查用户是否具有访问页面的管理员 ID?

[英]How to check if user has admin id to access page?

How to check if user has the $AdminID to access page?如何检查用户是否有 $AdminID 访问页面? $_SESSION['iroles'] is my discord roles $_SESSION['iroles'] 是我的 discord 角色

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;
    }
}
//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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM