php会话目录权限拒绝


php session directory permission deny

我是php 的新手

这是登录页面脚本

<?php include('dbconnect.php');
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    $admins_sql = "SELECT * FROM  administrator WHERE   username = '" .$username. "' AND password = '".md5($password). "' AND status = 'Active'";
    $admin_exe = mysql_query($admins_sql, $con);
    //Setting session variable
    $admin_row=mysql_fetch_array($admin_exe);
    $_SESSION['username'] = $admin_row['username'];
    $_SESSION['type'] = $admin_row['type'];
    IF($_SESSION['type'] == 'Admin') {header("Location:admin");exit(); }
    IF($_SESSION['type'] == 'Main') {header("Location:main");  exit(); }
    IF($_SESSION['type'] == 'Teaching') {header("Location:Teaching"); exit(); }
    IF($_SESSION['type'] == 'Exam Cell') {header("Location:Exam Cell"); exit(); }
    IF($_SESSION['type'] == 'Non-Teaching') {header("Location:Non-Teaching"); exit(); }
    IF($_SESSION['type'] == 'Library') {header("Location:Library"); exit(); }
    IF($_SESSION['type'] == 'Main') {header("Location:office"); exit(); }
    IF($_SESSION['type'] == 'Placement') {header("Location:Placement"); exit(); }
    IF($_SESSION['type'] == 'Systems') {header("Location:CC"); exit(); }
    IF($_SESSION['type'] == 'student') {header("Location:student"); exit(); }
?>

具有如上面脚本中重定向中所示的文件夹。

我的问题是,如果一个教学类型的用户登录,他们将被重定向到显示url IP地址/主文件夹名称/Taching/index.php。他们可以将url中的教学更改为admin,然后进入admin文件夹并访问admin功能。

我想要的是一种类型的用户不要进入另一种类型用户文件夹。

例如,在主页面顶部,您应该验证访问权限,并对您拥有的每个区域执行同样的操作。还有其他方法可以做到这一点,但这种方法应该适合你想要的。

session_start();
if( !isset( $_SESSION['type'] ) AND $_SESSION['type'] != 'Main' ) {
    header("Location: AccessDenied");
}