Jump to content

Redirect two different users to separate pages based on their login name


igor221189

Recommended Posts

Hello,

 

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've tried doing a couple of switch statements (shown as comments) like so: if login is student, then redirect to role.php and if login is tutor, then redirect to record.php. But they didn't work.

 

Table structure for members table from where login credentials are checked is as follows:

 

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

	//	$login="student";
	//	$login="tutor";

	//	switch ($login)
	//	{
	//	case "student":
	//	header("location: role.php");	
	//	break;

		//case "tutor":
		//header("location: record.php");	
		//break;
	//	}


		exit();
	}else {
		//Login failed
		header("location: login-failed.php");
		exit();
	}
}else {
	die("Query failed");
}

Link to comment
Share on other sites

Doesn't it work better like this?

 

	
$login="student";
$login="tutor";

if($login == "student"){
	header("location: role.php");	
}else{
	header("location: record.php");	
}

 

Dunno for sure, it's been a lot time since i've done some php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.