mediasreamer Posted October 10, 2008 Share Posted October 10, 2008 Hi, I currently have a php/mysql login page that works fine, but I'd like to incorporate some code that redirects users to specific pages based on login info. Since I'm very new to PHP (like 15mins!), any assistance would greatly be appreciated! Here's a piece of my login.php script: session_start(); require("dbconnect.php"); $log = "SELECT * FROM tbl_user_accts WHERE uname='".$_POST['uname']."'"; $qlog = mysql_query($log) or die("Cant Get UserData!"); $rlog = mysql_fetch_array($qlog); if($rlog['proj_id']=='0') { $error = "The Project for this account is already deleted!"; include ("index2.php"); } elseif(($_POST['uname'] == $rlog['uname']) && ($_POST['pw'] == $rlog['pw']) && ($_POST['uname']!='') && ($_POST['pw']!='')) { setcookie("user", "active", time()+3600); mysql_query("INSERT into tbl_logs (uid, last_log) VALUES ('".$rlog['uid']."',now())") or die(mysql_error()."Cant Write Log!"); $_SESSION['uid'] = $rlog['uid']; $_SESSION['pid'] = $rlog['proj_id']; header('Location:main.php?uid='.$rlog['uid']); More info about login: upon creation, each user name is assigned to a specific project. The database assigns a project id (proj_id) to each. As for the user_accts table, here are the variables: uid, uname, pw, proj_id and proj_type. What I'd like to happen: after authentication and a project id is identified, I'd like the login script to check the "proj_type" variable in the user_accts database for that project id. I've assigned values of "live" and "archive" to "proj_type". Each project with have one or the other. If a project is "live", the login script will redirect to live.php; if "archive, then archive.php. I think I need 2 IF statements before the header command. That's as far as my PHP knowledge goes. Thanks for your help! Jeff Quote Link to comment https://forums.phpfreaks.com/topic/127816-solved-custom-login-script-redirecting-users-to-different-pages/ Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 <?php $sql = "SELECT proj_type FROM tableName WHERE user_id='$rlog['uid']'"); $result = mysql_query($sql) or trigger_error("query failed" . mysql_error()); $row = mysql_fetch_assoc($result); //now an if statement to see if($row['proj_type'] == 'archive') { //redirect to archive pages.. } elseif($row['proj_type'] == 'live' { //redirect to live pages... } else { //handle the error } ?> This is untested but i think its on the right lines to get you going... Quote Link to comment https://forums.phpfreaks.com/topic/127816-solved-custom-login-script-redirecting-users-to-different-pages/#findComment-661712 Share on other sites More sharing options...
mediasreamer Posted October 10, 2008 Author Share Posted October 10, 2008 Thanks Ben Dude! I appreciate it. Jeff Quote Link to comment https://forums.phpfreaks.com/topic/127816-solved-custom-login-script-redirecting-users-to-different-pages/#findComment-661769 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.