登录页面 - 检测用户类型,并带他到他们的主页 [英] Login Page - Detecting the user type and lead him to their main pages
问题描述
我有一个基本的登录页面。我目前使用users表,其中我有用户名和密码列。我的系统有3种类型的用户:主要,学术主任和讲师。事实是,我为每个用户创建表。我如何检测他们并将他们导向他们的主页?例如对于讲师用户,我有2个colmmns lecusername和lecpasswprd。
I have a basic login page. I currently use a users table in which I have username and password columns. My system has 3 types of users: principal, academic director and lecturer. The truth is that I created table for each of the users. How can I detect them and direct them to the their main pages? For example for the lecturer user I have 2 colummns lecusername and lecpasswprd.
<html>
<head><h1>Login Page</h1>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<form action = "login.php" method = "POST">
Username: <input type="text" name="username"> <br /><br/>
Password: <input type="password" name="password"> <br /><br/>
<input type="submit" value="Login" name="submit">
</form>
</center>
</body>
</html>
<?php
$error ='';
require('connect.php');
$username = @$_POST['username'];
$password = @$_POST['password'];
if(isset($_POST['submit']))
{
if($username && $password)
{
$check = mysql_query("SELECT * FROM users WHERE username='".$username."' AND password= '".$password."'");
$rows = mysql_num_rows($check);
if(mysql_num_rows($check)!=0)
{
session_start();
header("location:/main.php");
exit();
}
else
{
echo "Couldn't find username.";
}
}
else
{
echo "Please fill all the fields.";
}
}
?>
推荐答案
您的表应该有另一个定义为userType的列。
Your table should have another Column defined as userType.
Select语句应返回该列。
The Select statement should return that column.
$check = mysql_query("SELECT userType
FROM users
WHERE username='".$username."'
AND password= '".$password."'");
现在您应该阅读userType
Now you should read what is the userType
$rows = mysql_fetch_row($check);
if($rows[0] == "admin")
{
session_start();
header("location:/admin.php");
}
这篇关于登录页面 - 检测用户类型,并带他到他们的主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!