Page 1 of 1

[SOLVED] - Redirecting users to different pages in LOGIN

Posted: Sat Aug 07, 2010 4:54 am
by Bbob
Hi

Im having trouble try to figuring out on how to redirect two different types of users to two different pages in a single login form.


Basically what I want is if a regular user logs in, he will be directed to user_mainpage.php but if the website administrator logs in, he will be directed to admin_mainpage.php. Both of them will use the same login form. Is this possible? If so, can you please teach me how to code this.


Thanks in advance.

Re: Please help - redirecting users to different pages in LO

Posted: Sat Aug 07, 2010 4:57 am
by pbs
Is there any differentiating factor between this 2 users (admin and user). According to that you can redirect the logging user.

Re: Please help - redirecting users to different pages in LO

Posted: Sat Aug 07, 2010 5:31 am
by Bbob
Hi, thanks for the reply


Sorry I forgot to add that.

To differentiate an admin from the user, I added a column in the database table named Type. If the type = admin, then person logging in is an administrator. If the type = user, then the person is logging in as a user.

I still couldnt picture how to do that even if I have the type to differentiate the 2 users. All I can think of is to make a PHP if statement then somehow filter by an SQL statement, but I dont think thats possible.

Re: Please help - redirecting users to different pages in LO

Posted: Sat Aug 07, 2010 6:54 am
by manojsemwal1
add one more column in sql usertype and put the status of Admin= A and user =u
in log in page when admin login with his username and paasword that time fetch the value form login table againt user name and paasword like

select Username,password,usertype from logintb where username='' and password='';

if the value will be match it will return 1 else 0
then use if statement
if(usertype=='A')
{
header("Admin.php");
}
else
{
header("client.php");
}

Thanks.

Re: Please help - redirecting users to different pages in LO

Posted: Sat Aug 07, 2010 7:56 am
by Bbob
Cool!

Thanks it worked!

Thanks guys, for the reply especially to manoj for providing the solution.

============================================================

UPDATE: It worked kinda. Sorry for the false alarm

The code provided worked but the else statement seems to be the only one working.

Here's my code maybe you guys can find out whats wrong:

Code: Select all

$sql="SELECT * FROM $tbl_name WHERE UserName='$username' AND Password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1)
{
if (type=='u')
	{
		$_SESSION['username'] = $username;

		header("location:user_myaccount.php");
	}
	
else
	{	
		$_SESSION['username'] = $username;

		header("location:admin_main.php");
	}
}

Re: Please help - redirecting users to different pages in LO

Posted: Sat Aug 07, 2010 8:02 pm
by Bbob
Hi

I manage to solve this puzzle

Here's the code

Code: Select all

if ($count == 1)
{
	$_SESSION['dbusername'] = dbusername;
	
	while ($row = mysql_fetch_assoc($result))
	{
		$usertype = $row['type'];
		
		if ($usertype==user)
		{
			header("location:user_myaccount.php");
		}
		
		else
		{
			header("location:admin_main.php");
		}
	}
}