网站的管理页面只有由管理员访问,如果有人试图访问它,它重定向到登录页面


admin page of website only to be accessed by admin if someone tries to access it , it redirects to login-page

这是我写的代码

if(!isset($_SESSION['authenticated'])){header("location:login.php");}

但是这个代码不工作,它正在被访问

能否将变量设置为真或假?

if ($_SESSION['authenticated']) {
   // Admin page here...
} else {
   // Redirect to another page...
   header("Location: login.php");
   die();
}
编辑:

我说将其设置为true或false的原因是您可以通过将其设置为false来注销用户。而不是取消变量。

编辑:

  • 删除不需要的= true

您在header函数中错过了大写L,您需要在重定向后杀死该页面。

代替

header('location:index.php');

header("Location: login.php");
die();