用户角色PHP登录后重定向

时间:2018-01-30 05:50:43

标签: php html mysql

我在堆栈上浏览了多篇文章但是我没有运气,所以我想我会问。 我有一个Mysql数据库

company has many employees
company has many tasks
employees have many tasks

我希望这两个用户能够在同一区域登录,但我希望将R用户类型重定向到像/index.php这样的页面,而将A的任何人重定向到/ index .PHP

1 个答案:

答案 0 :(得分:0)

像这样构建你的项目(仅举例):

project
 -index.php //where R type user will be navigated
 -aindex.php //where A user type will be navigated
 -login.php //this is where the login form is, set your form action="login_logic.php"
 -login_logic.php //this is where the form submits login details and check the user type

在你的login_logic.php中:

if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];

sql = SELECT * FROM users WHERE username = '$username'; //I am skipping this as you seem to know how to query ...smthing like that
//then check for password and verify user and get the usertype



//after getting the usertype check the type then simply re-direct
if(user['userType'] == "R"){
 header("Location:index.php");
 } elseif(user['usertype'] =="A"){
 header("Location:a/index.php");
}

}