[英]How to restrict a particular user to access the particular webpage
I want to restrict users to access particular webpages in my applicatipn. 我想限制用户访问我的应用程序中的特定网页。 In my application I have 4 webpages like
Mumbai
, Delhi
, Bangalore
, Kolkata
and I have havie 4 users say User1
, User2
, User3
and User4
. 在我的应用程序中,我有4个网页,如
Mumbai
, Delhi
, Bangalore
, Kolkata
,还有4个用户说User1
, User2
, User3
和User4
。 All users are Admin. 所有用户均为管理员。
My requirement is that all 4 user can't access Mumbai
page, User1
can access only Delhi
page, User2
and User3
can access only Bangalore
page and User4
can access only Kolkata
page. 我的要求是所有4个用户都不能访问
Mumbai
页面, User1
仅可以访问Delhi
页面, User2
和User3
仅可以访问Bangalore
页面,而User4
仅可以访问Kolkata
页面。
For Mumbai page I used 对于我使用的孟买页面
if($login_session['login_user'] != 'User1, User2, User3, User4')
{
echo "You dont have permission to access this page";
echo '<meta http-equiv="refresh" content="1; url=Admin-Dashboard.php">';
exit();
}
?>
And for Delhi page I used Following code but it is not working 对于德里页面,我使用了以下代码,但它不起作用
if($login_session['login_user'] != ' User2, User3, User4')
{
echo "You dont have permission to access this page";
echo '<meta http-equiv="refresh" content="1; url=Admin-Dashboard.php">';
exit();
}
?>
The problem is that 'User1, User2, User3, User4'
is a string. 问题是
'User1, User2, User3, User4'
是一个字符串。 You need to explode()
that or somehow make sure that the users are in an array: 您需要
explode()
或以某种方式确保用户位于数组中:
$allowed_users = array('User1','User2','User3');
if (!in_array($login_session['login_user'], $allowed_users)) {
echo "You dont have permission to access this page";
echo '<meta http-equiv="refresh" content="1; url=Admin-Dashboard.php">';
exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.