Eliasam13 Posted November 30, 2007 Share Posted November 30, 2007 Hello, Iv searched everywhere trying to find the answer to my problem... Im trying to make a login form (Username / Password Authentication) and for each user that has a login / password they will be redirected to a specific page.. for example if the user "Mike" log's in he will be directed to page1. If the user "Jon" log's in he will be directed to page2. And really the only login i know how to do is to direct all users to one location... I hope someone can help me!! Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 30, 2007 Share Posted November 30, 2007 what makes page 1 different from page 2? my idea is to associate the primary key of this table with the page number to go to Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 30, 2007 Share Posted November 30, 2007 That sounds like an awful lot of maintenance. Why would you want to do that? You'd be better off with a dynamic approach whereby you pass an ID or a username to the logged-in location, and load the appropriate content based on that variable. Quote Link to comment Share on other sites More sharing options...
Eliasam13 Posted November 30, 2007 Author Share Posted November 30, 2007 This is what im trying to do... My customer will have there own username and password. Each of the customers will go to a specific page relating to there information. Page 1 Will Have information regarding customer "Mike". Having information such as his Name and address, his recent purchase, etc.. Page 2 Will be the same thing but information related to "Jon". thats what im trying to do.. How can I redirect all my cutomers to there OWN specific page in php? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted November 30, 2007 Share Posted November 30, 2007 Why don't you just make the account page dynamic by calling from a database. e.g. When the user logs in, start a session calling the username from the form.. Login process: <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; $sql = mysql_query(sprintf("SELECT * FROM `users` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", $username, $password)) or die('Error: ' . mysql_error()); if($obj = mysql_fetch_object($sql)) { $_SESSION['valid'] = true; $_SESSION['username'] = $username; echo '<script type="text/javascript">window.location = "account.php";</script>'; } else { echo 'Your credentials appear to be invalid.'; } ?> Then for the account page: <?php session_start(); if($_SESSION['valid']) { $username = $_SESSION['username']; $sql = mysql_query(sprintf("SELECT * FROM `users` WHERE `username` = '%s' LIMIT 1", $username)) or die('Error: ' . mysql_error()); if($obj = mysql_fetch_object($sql)) { echo 'Username: ' . $username; echo 'E-Mail Address: ' . $obj->email; } } else { echo 'You are not logged in.'; } ?> This is a very basic example. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 30, 2007 Share Posted November 30, 2007 Why do this: echo '<script type="text/javascript">window.location = "account.php";</script>'; Why use Javascript for something that could easily be done with header(), remember that not everyone has Javascript enabled. Quote Link to comment Share on other sites More sharing options...
Eliasam13 Posted November 30, 2007 Author Share Posted November 30, 2007 ok i understand what you mean but for adding the specific customer information i would have to put all that info in mysql right? Quote Link to comment Share on other sites More sharing options...
Bramme Posted November 30, 2007 Share Posted November 30, 2007 yes indeed. it would be much easier to extend your existing users table like this as it is now (i'm guessing) user_id | name | password as it should be user_id | name | password | a | field | for | everything | you | want | to | save. And then in your code when the user has entered the correct login and password, you should add smth like $_SESSION['userid'] = $id (where $id could be fetched from the database). Next, you redirect them all to the same page which has a table like <?php $userid = $_SESSION['userid']; $userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE user_id = $userid)); echo "<ul>\n<li>Name: $userdata['name']</li>\n<li>Field: $userdata['field']</li>\n</ul>"; ?> Something like that... Quote Link to comment Share on other sites More sharing options...
Wolphie Posted November 30, 2007 Share Posted November 30, 2007 Header wouldn't be able to be used along with starting a session at the beginning. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 30, 2007 Share Posted November 30, 2007 Header wouldn't be able to be used along with starting a session at the beginning. Yes it would. Quote Link to comment Share on other sites More sharing options...
Bramme Posted November 30, 2007 Share Posted November 30, 2007 Header wouldn't be able to be used along with starting a session at the beginning. ob_start; workaround? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 30, 2007 Share Posted November 30, 2007 Header wouldn't be able to be used along with starting a session at the beginning. ob_start; workaround? You don't need output buffering. Yes, you cannot send headers after output to the browser without using output buffering, but starting a session and assigning session variables does not output anything to the browser. Quote Link to comment 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.