我有一个包含表用户的数据库。在用户表上,我有一个值为“corny”和用户名=“admin”的用户名。
在我的 user.php 上我有这个代码
if(!isset($_SESSION['username'])){
header('location: index.php');
}
在我的 admin.php 上我有这个 session
if(!isset($_SESSION['username'])){
if($_SESSION['username'] != "gft-admin"){
header('location: index.php');
}
}
所以我的问题是从users.php我可以访问admin.php。如果 user 不等于 'admin',我应该怎么做才能避免 users.php 访问 admin.php。
最佳答案
您当前的逻辑是:
IF there is no username
THEN if the username is not gft-admin
THEN REDIRECT
但是你想说的是:
IF there is no username
OR if the username is not gft-admin
THEN redirect
您会这样表达:
if(!isset($_SESSION['username']) || $_SESSION['username'] != "gft-admin"){
header('location: index.php');
}
关于php - 用户可以使用 php 中的 session 访问管理页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33186682/