简体   繁体   中英

Redirect after login by User Role PHP

I've browsed multiple articles on stack but I've had no luck with this so I thought I would ask. I have a Mysql Database

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

I would like both of these users to be able to login in the same area, but I would like the R user type to be redirected to a page like /index.php while anyone with A will be redirected to a/index.php

structure your project like this (just for example):

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

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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