简体   繁体   中英

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.

Its not working. any help is appreciated.

Remember to destroy $_SESSION['roles']=='1' after admin logged out. This might be because of session value of admin not destroyed and you tried loginin with userid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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