mdemetri2 Posted May 22, 2013 Share Posted May 22, 2013 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!! Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/ Share on other sites More sharing options...
Muddy_Funster Posted May 22, 2013 Share Posted May 22, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/#findComment-1431517 Share on other sites More sharing options...
mdemetri2 Posted May 22, 2013 Author Share Posted May 22, 2013 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!! Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/#findComment-1431587 Share on other sites More sharing options...
mdemetri2 Posted May 23, 2013 Author Share Posted May 23, 2013 Hi, anyone got any ideas on this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/#findComment-1431829 Share on other sites More sharing options...
Muddy_Funster Posted May 23, 2013 Share Posted May 23, 2013 where did you get that login script? it's seriously out of date. You would add another if check within the if($count==1), but I suggest getting a better login script first. Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/#findComment-1431833 Share on other sites More sharing options...
mdemetri2 Posted May 24, 2013 Author Share Posted May 24, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278267-redirect-based-on-user-type/#findComment-1432034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.