访问级别和身份验证(PHP/MYSQL)

访问级别和身份验证(PHP/MYSQL),php,mysql,login,login-script,access-levels,Php,Mysql,Login,Login Script,Access Levels,我有这个脚本工作得很好。但是我在utype\U id可以在其他utype\U id中访问时遇到问题。我如何对其进行身份验证,以便utype\U id=1无法访问utype\U id=2?代码如下 <?php session_start(); include('includes/connection.php'); $username=$_POST['username']; $password=$_POST['password']; if(!empty($username) &&

我有这个脚本工作得很好。但是我在utype\U id可以在其他utype\U id中访问时遇到问题。我如何对其进行身份验证,以便
utype\U id=1
无法访问
utype\U id=2
?代码如下

<?php
session_start();

include('includes/connection.php');

$username=$_POST['username'];
$password=$_POST['password'];

if(!empty($username) && !empty($password))
{

    $command="select * from user WHERE  username = '".$username."' and password='".$password."'";

    $result1=mysql_query($command);
    $count=mysql_num_rows($result1);

    $utype_id = "SELECT utype_id FROM user WHERE username='$username'";
    $result2 = mysql_query($utype_id);
    $result3 = mysql_fetch_row($result2);

    if($count==0)
    {
        header("location:loginform.php?attempt=fail");
    }
    else {
        $sql="select * from user WHERE username='".$username."'";
        $result=mysql_query($sql);
        while($row=mysql_fetch_row($result)){

            $_SESSION["id"]=$row[0];
            $_SESSION["username"]=$row[5];
            $_SESSION["name"]=$row[2];

            switch($result3[0]){

            case '1':
                header("location: module1/index.php");
                break;

            case '2':
                header("location: module2/index.php");
                break;

            case '3':
                header("location:loginform.php?attempt=unauthorized");
                break;
            }
        }
    }
}
else
{
    header("location:loginform.php?attempt=null");
}
?>

遵循代码剪切额外查询和长脚本
为什么要在三个查询中查询相同的用户详细信息??1个查询如果用于选择用户。2表示用户的utype_id。联合收割机取穗行为3。它起作用了。但问题是utype_id 1可以访问utype_id 2。这不应该是..请检查我下面的代码,也许对你有帮助..我试试这个。。模块1和模块2的每个index.php上是否有任何身份验证?获取和错误分析错误:语法错误,意外'第16行的D:\WAMP\www\ptoms\login.php中的“{”是每个用户一个模块,如果是,请在用户会话中保留utype_id并验证用户是否直接访问未经授权的模块。其每个用户类型1是其他类型的用户。2是另一类型的用户。每个用户都有特定的用户类型。如果他/她是用户类型1,他/她可以访问模块1。如果他/她是用户类型2他可以访问模块2。是的,他们都可以访问模块1和模块2,这对我来说是个大问题:(最好使用sperate表来维护用户模块。也可以使用逗号分隔的值来维护多个模块。我不知道。但是脚本工作得很好。我的问题是用户1可以访问用户2模块,反之亦然。其他一切都很好。
            include('includes/connection.php');

            $username=$_POST['username'];
            $password=$_POST['password'];

            $location = 'loginform.php?attempt=null';

            if(!empty($username) && !empty($password))
            {

            $command="select * from user WHERE  username = '".$username."' and password='".$password."'";
            $result=mysql_query($command);

            $location = 'loginform.php?attempt=fail';
            if(mysql_num_rows($result) > 0 {
                $frUser = mysql_fetch_array($result, MYSQL_BOTH);
                $_SESSION["id"]=$frUser['id']; // Change the name here
                $_SESSION["username"]=$frUser['username'];// Change the name here
                $_SESSION["name"]=$frUser['name'];  // Change the name here
                $utypeId = $frUser['utype_id'];
                switch($utypeId) {
                case '1':
                    $location = 'module1/index.php';
                break;
                case '2':
                    $location = 'module2/index.php';
                break;
                case '3':
                    $location = 'loginform.php?attempt=unauthorized';
                break;
                }   
            }
            }
            header("location:".$location);
            ?>