如何确保只有type="admin"的用户才能访问例如admin.php
例如。我已经注销了。但我仍然可以访问admin.php,我如何确保我只能访问页面时,我作为一个管理员登录?
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
while($row = mysql_fetch_array($result)){
//remove this line ******header("location:customer_home.php");
if($row['type'] == 'admin'){
header("location: admin.php");
} else if($row['type'] == 'customer'){
header("location: customer_home.php");
}
}
}
最简单的解决方法是
if($row['type'] == 'admin'){
$_SESSION['isAdmin'] = true;
header("location: admin.php");
}
在admin.php文件中:
if($_SESSION['isAdmin']==true){
print 'hi admin!';
}
然而,这是一个'基本'版本,我建议查找PHP安全性,并查找用户登录ID与数据库中的表,以正确检查用户登录凭据