用不同的用户级别PHP登录

时间:2013-02-10 19:15:04

标签: php sql

请帮忙。这段代码有什么问题。我正在尝试创建具有不同用户级别的登录,但是当我尝试以管理员或其他用户身份登录时,它没有直接到请求页面。

这是代码

<?php
...//the problem goes here, it didn't direct to the request page

if(empty($error)){//if the array is empty , it means no error found
    $query_check = "SELECT * FROM users WHERE (email = '$email' AND password= '$password') AND activation IS NULL";
    $result = mysqli_query($db_conn, $query_check);
    if(!$query_check){
    echo "Query Failed";        
    }
    if(@mysqli_num_rows($result)==1){//if match
        $_SESSION = mysqli_fetch_array($result,MYSQLI_ASSOC); //Assign the result of this query to SESSION Global Variable
        $row = mysqli_fetch_array ($result, MYSQLI_ASSOC);
            if($row['role_type']=='admin'){
                header("Location:../views/admin/dashboard.php");
                exit;
            }
            if($row['role_type']=='staff'){
                header("Location:../views/staff/dashboard.php");
            }
            if($row['role_type']=='patient'){
                header("Location: ../views/dafault/home.php");
            }
    }else{
        $msg_error = "Either Your Account is inactive or Email address /Password is Incorrect";
    }
}else{
    echo '<div class="errormsgbox"> <ol>';
    foreach($error as $key => $values){
        echo '  <li>'.$values.'</li>';
    }
    echo '</ol></div>';
}

if(isset($msg_error)){
    echo '<div class="warning">'.$msg_error.' </div>';
    }
mysqli_close($db_conn);
}

&GT;

1 个答案:

答案 0 :(得分:0)

标头功能应包含完全限定的URL,而不是相对文件系统路径。

header('Location: http://www.example.com/views/admin/dashboard.php');