Roboff Posted June 29, 2011 Share Posted June 29, 2011 I am still learning PHP and have read and tried many different things but can't get any of them to work. I need help with this one, PLEASE! I have a working login script that uses PHP and a database for my login. My database has a table name clientpage with fields id, username, password, clientpage. When the user logs in they are redirected to userarea.php. header("Location: userarea.php") What I need to know is how I can redirect each one of my clients to their own page depending on the username they enter. The clients pages are very unique so I can't redirect to the same page and just change the data. Example: id - 1 username - cologicsystems password - secret1 clientpage - client1.php id - 2 username - nocore password - secret2 clientpage - client2.php and so on...... PLEASE HELP. I need this to work in 2 days. Thank you MY PAGES login.php <?php include 'functions.php'; if (loggedin()) { header("Location: userarea.php"); exit(); } if($_POST['login']) { $username = $_POST['username']; $password = $_POST['password']; $rememberme = $_POST['rememberme']; if ($username&&$password) { $login = mysql_query("SELECT * FROM users WHERE username='$username'"); while ($row = mysql_fetch_assoc($login)) { $db_password = $row['password']; if ($password==$db_password) $loginok = TRUE; else $loginok = FALSE; } if ($loginok==TRUE) { if ($rememberme=="on") setcookie("username", $username, time()+7200); else if ($rememberme=="") $_SESSION['username']=$username; header("Location: userarea.php"); exit(); } else echo "Username/password combination incorrect.<p />"; } else die("Hit back and enter a username and password."); } ?> <form action="login.php" method="POST"> Username:<br/> <input type="text" name="username"><p /> Password:<br/> <input type="password" name="password"><p /> <input type="checkbox" name="rememberme"> Authorized user<br /><br /> <input type="submit" name="login" value="Log in"> </form> functions.php <?php //session session_start(); // connect to database $connect = mysql_connect("localhost","arc_robert","arc") or die("Could not connect"); mysql_select_db("arc_rememberme") or die("Could not find db"); //login check function function loggedin() { if (isset($_SESSION['username'])||isset($_COOKIE['username'])) { $loggedin = TRUE; return $loggedin; } } ?> userarea.php <?php include 'functions.php'; if (!loggedin()) { header("Location: login.php"); exit(); } ?> You are logged in!<p /> <a href="logout.php">Log out</a> logout.php <?php session_start(); //destroy session session_destroy(); //unset cookies setcookie("username","",time()-7200); header("Location: login.php"); ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/ Share on other sites More sharing options...
TeNDoLLA Posted June 29, 2011 Share Posted June 29, 2011 When you fetch the data from the db and check if the user has logged in succesfully. If he logged in just use the database information for the clientpage to redirect the user. And please use code tags, thats a mess to read long codes without them. if ($loginok == TRUE) { header('Location: ' . $row['clientpage']); } Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1236178 Share on other sites More sharing options...
Roboff Posted June 30, 2011 Author Share Posted June 30, 2011 Thanks for the reply, but I tried that already. But when it redirects it goes back to the main index page instead of the database clientpage. No errors at all, it just doesnt redirect to what is in the database. Still not working.... Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1236706 Share on other sites More sharing options...
revraz Posted June 30, 2011 Share Posted June 30, 2011 Set a session in your login.php and then check that session variable on your other pages to determine if they are logged in or not. Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1236710 Share on other sites More sharing options...
Roboff Posted June 30, 2011 Author Share Posted June 30, 2011 The $username session variable is set in the login.php. When it redirects to the userarea.php the username session is still set. What i need to know is how to query the $username session and then have it redirect to different pages depending what the $username session is? Any direction on how to do this would be great. Please teach... or tell me what im doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1236712 Share on other sites More sharing options...
EdwinPaul Posted June 30, 2011 Share Posted June 30, 2011 When you fetch the data from the db and check if the user has logged in succesfully. If he logged in just use the database information for the clientpage to redirect the user. And please use code tags, thats a mess to read long codes without them. if ($loginok == TRUE) { header('Location: ' . $row['clientpage']); } If you need this $row['clientpage'] in another script, you have to put it in a session-variable as well. Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1236719 Share on other sites More sharing options...
Roboff Posted June 30, 2011 Author Share Posted June 30, 2011 Okay, I have worked on this for 5 days straight and still cant make it work. I am out of time and have to have this working asap. I have tried to learn it myself and I read 100's of different tutorials, but cant make it work, and now I am out of time. So...... Where is the best place online to pay someone to fix this for me quickly. I need it done by tomorrow. Also thank you to all who answered and tried to help. Quote Link to comment https://forums.phpfreaks.com/topic/240666-php-database-login-redirect/#findComment-1237070 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.