Jump to content

Redirect based on user type?


mdemetri2

Recommended Posts

Hello

 

Had some great help on here, and wondered if someone could help here too. If after has entered login details, and successfully got to the main page, is it possible to add in a function to check the user type and redirect to specific page?

 

I have tried to find some working examples but most of these are members / non member based and I might want 3 or 4 types of user, so different start pages for each after a successful login.......

 

Much appreciated!!

 

 

Link to comment
Share on other sites

Sure you can, there are a couple of ways of doing this, you can store the destination pages in the database along with the group definitions, or you can hard code them into an if() in your php.

 

loading them into the database is the most flexible, you would then grab the destination during the login query and apply it to the header(location: ) on success. the php method would have you grab the group type, or roll level during the login query and then run it through a series of if() elseif() checks to fire the chosen header(location: ) call.

Link to comment
Share on other sites

Thanks for the reply Muddy_Funster, I have adopted this code that currently allows me to login to my site, view main page that only has some text at the moment and welcome 'username', logout, and show an incorrect login attempt. Do I add what you suggest somewhere near the bottom by the headers as an and after the username and password has been checked.....

<?php require_once('Connections/Connection1.php'); ?>

<?php
$tbl_name="users"; // Table name 

mysql_select_db($database_Connection1, $Connection1);

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=md5($_POST['mypassword']); 



// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE userid='$myusername' and password='$mypassword'";
$result=mysql_query($sql);



// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:main.php?myusername=".$myusername);
}
else {
header("location:login_failed.php");
//echo "Wrong Username or Password";
}
?>

Thanks muchly!!

Link to comment
Share on other sites

it's something that has been in place for a while and not changed, so thought I would just carry on with it. Playing around really.

 

I will take a look at what you suggest, and maybe look at an alternative login script....

 

Thanks again.

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.