[英]restrict page access in php
I am trying to restrict page access with role please have a look at my code. 我试图用角色限制页面访问,请查看我的代码。
<?php
session_start();
echo $_SESSION['user']; echo"<br/>";
echo $_SESSION['roles'];
if($_SESSION['user']==true ){
if($_SESSION['roles']=='1'){
echo "Welcome User";
}else{ echo "You don't have acces to this page";}
}else{
header('location:index.php');
}
?>
Every user can enter admin page. 每个用户都可以进入管理页面。 I want only particular roles to be switched to Admin page restricting others.
我只希望将特定角色切换到“管理”页面以限制其他角色。 I am managing it with if condition here.
我在这里用if条件进行管理。
Its not working. 它不起作用。 any help is appreciated.
任何帮助表示赞赏。
Remember to destroy $_SESSION['roles']=='1'
after admin logged out. 记住在管理员注销后销毁
$_SESSION['roles']=='1'
。 This might be because of session value of admin not destroyed and you tried loginin with userid. 这可能是因为admin的会话值未破坏,并且您尝试使用userid登录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.