根据他们的登录名将两个不同的用户重定向到单独的页面
我希望能够根据用户的登录名将其重定向到其他页面.此刻,下面的代码将所有用户重定向到同一页面(role.php),无论他们的登录名是什么.我有两个用户:学生和导师.这两个用户都被重定向到role.php. 但是,我想将学生用户重定向到role.php,将导师用户重定向到record.php.我考虑过要执行几个if语句,如果member_id为1,然后重定向到role.php,如果member_id为2,然后重定向到record.php.但是无法这样做.
I would like to be able to redirect a user to a different page based on their login name. At the moment, the code below redirects all users to the same page (role.php) no matter what their login is. I have two users: student and tutor. Both of these users are redirected to role.php. However, I would like to redirect student user to role.php and tutor user to record.php. I thought about doing a couple of if statements if member_id is 1, then redirect to role.php and if member_id is 2, then redirect to record.php. But was unable to do so.
从中检查登录凭据的成员表的表结构如下:
Table structure for members table from where login credentials are checked is as follows:
member_id:1或2 登录:学生,导师 passwd:每个用户的单独密码-使用md5加密.
member_id: 1 or 2 login: student, tutor passwd: separate password for each user – encrypted with md5.
任何帮助将不胜感激.谢谢.
Any help would be greatly appreciated. Thanks.
//Create query
$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
session_write_close();
header("location: role.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
}else {
die("Query failed");
}
使用switch语句,但现在所有用户都重定向到record.php.我认为我没有正确使用switch语句.
Switch statement used but now redirects to record.php for all users.I think I'm not using the switch statement correctly.
$login="student";
$login="tutor";
switch ($login)
{
case "student":
header("location: role.php");
break;
case "tutor":
header("location: readonlystu.php");
break;
}
我会去找有关该角色的switch语句.
I'd go for an switch statement on the role.
switch($iRoleId)
{
case ROLE_STUDENT:
// do stuff
break;
case ROLE_TUTOR:
// do stuff
break;
}