如何通过用户类型在php和mysql中重定向到不同的页面 [英] How to redirect into different page by user type in php and mysql

查看:90
本文介绍了如何通过用户类型在php和mysql中重定向到不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从同一登录页面重定向用户.

I want to redirect the users from the same log-in page.

文件夹结构...

root
|
--------/application/app.php <---------- for normal user
|
--------/administration/admin.php <------- for admin user
|
-------- index.php (Log-in page)

用户表

ID       USER_NAME       PASSWORD      USER_TYPE
1         admin           pass@admin    admin
2         user            pass@user     user

如果登录用户的用户类型为admin,则他/她将被重定向到/administration/admin.php否则为/application/app.php.

If the login user's user type is admin then he/she will be redirected to /administration/admin.php else /application/app.php.

我该怎么办?

此致

推荐答案

检查用户名和密码后.在这种情况下,您可以检查其用户类型并将其保存到变量中. $ user_type .

After checking the username and password. You can check their usertype and save it to a variable in this case $user_type.

$ user_type = $ row ['user_type']//从数据库中的表行获取用户的用户类型

$user_type = $row['user_type'] //get the usertype of the user from table row in your database

if( $user == 1){ //check if user or password is correct from query


 if($user_type == "normal user"){ //check usertype

    header("Location:/application/app.php"); //if normal user redirect to app.php

    }else{

    header("Location:/administration/admin.php"); //if admin user redirect to admin.php

    }
}

这篇关于如何通过用户类型在php和mysql中重定向到不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆