繁体   English   中英

登录后通过用户角色PHP重定向

[英]Redirect after login by User Role PHP

我浏览了多篇文章,但是我对此没有运气,所以我想问一下。 我有一个Mysql数据库

username | password | userType
someguy1 | 1234567  | R
coolguy1 | @1234    | A

我希望这两个用户都可以在同一区域登录,但是我希望将R用户类型重定向到/index.php之类的页面,而将具有A的任何人都重定向到a / index.php

这样构造项目(例如):

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");
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM