heirani1 Posted June 20, 2008 Share Posted June 20, 2008 i created a login page and register page which people can login to, once they logged in they can upload files and stuff like that. what i want to do now is once the user has logged in to take them to there own page within my site. So basically every member gets there own page. how would i go about doing this becuase i don't have a clue. thanks for any suggestions... Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 in the login info table in database (where you save all the users with their password), you save the user's own page's address as well. Then in login page, where you validate username and password, use HEADER. //If successfully login // read $userpage from your database header ("location : $userpage"); Quote Link to comment Share on other sites More sharing options...
waynew Posted June 20, 2008 Share Posted June 20, 2008 Set up a table with all their info in it. Make sure their username or id is in it. User_ID | Username | Name | Age |.... Etc Then create a template page called profile.php Then once they log in, have: header("Location : profile.php?username=whateverusernametheyentered"); Make sure that the above code is placed BEFORE the starting HTML tag, just to be safe. On the profile page, you can have a $_GET. <?php session_start(); $user = $_GET['username']; echo $user; ?> Then you could use that info to take out all of the rest of the data relating to that username. Simple example, but should help. Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 thanks waynewex that sort of makes things a little clearer, using that code will create a different page for each user since your calling the username etc from the users database. Any chance you could implement your code into my login page so i can understand it better? heres the code .. <?php // Login // auth.php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['name']=$_POST["name"]; $_SESSION['password']=$_POST["password"]; } // query for a user/pass match $result=mysql_query("select * from registered_members where name='" . $_SESSION['name'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $num=mysql_num_rows($result); // print login form and exit if failed. if($num < 1){ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <div align="center">Please login...<br> <br> </div> <form method=POST action=index.php> <div align="center">username: <input type=text name="name"> password: <input type=password name="password"> <input type=submit value="Login"> </div> </form> <br /> <div align="center"><a href="signup.php">Not Registered? Register now!</a> </div> </body> <?php exit; } ?> </div> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 Set up a table with all their info in it. Make sure their username or id is in it. User_ID | Username | Name | Age |.... Etc Then create a template page called profile.php Then once they log in, have: header("Location : profile.php?username=whateverusernametheyentered"); why do you need to go to another page to get all the data of that user. You could do it right at the time of log in. Then you could use header to go to that user's page, and i think this is what he wants. //Database connections <?php if (isset($_POST['login'])) { $username = $_POST['username']; $password = md5($_POST['password']); $result = mysql_query("Select `username`,`password`,`userpage` From login_table where username='$username'"); if(mysql_num_rows($result)>0) { $row = mysql_fetch_array($result); if($password == $row["password"]) { // Save all necessary $_SESSION() variables $_SESSION[s_username]=$username; header ("location : $row['userpage']"); // then go to the user's page } else { echo "Password mismatch"; } } else { echo "No user found"; } } ?> Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 basically i want is when the user logs on to bring up a page the same as all the other users but the content to be different so when dave logs in it says welcome dave and then lists the stuff hes interested in for example, then when chris logs in welcome chris etc, which code would be best for that? and how would i implement it into my code? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 ok ... then go for waynewex's one. That'll be serving your purpose. Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 ok thanks abdbuet, the code you showed, what would that be best for? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 you can use that if, for example, I have a site where each user can design one page for him. So, once any user (say user1) registered, I'll give him a dedicated page (like www.mywebsite.com/userpage/user1.html) which he can design as he wish. So, whenever he logs in, I'll route him to his page. Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 o rite thats quite clever, i'm just trying to work out where to but this line of code.. header("Location : profile.php?username=whateverusernametheyentered"); sorry seems abit stupid but its confusing me. login page ... <?php // Login // auth.php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['name']=$_POST["name"]; $_SESSION['password']=$_POST["password"]; } // query for a user/pass match $result=mysql_query("select * from registered_members where name='" . $_SESSION['name'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $num=mysql_num_rows($result); // print login form and exit if failed. if($num < 1){ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <div align="center">Please login...<br> <br> </div> <form method=POST action=index.php> <div align="center">username: <input type=text name="name"> password: <input type=password name="password"> <input type=submit value="Login"> </div> </form> <br /> <div align="center"><a href="signup.php">Not Registered? Register now!</a> </div> </body> <?php exit; } ?> </div> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 <?php // Login // auth.php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['name']=$_POST["name"]; $_SESSION['password']=$_POST["password"]; } // query for a user/pass match $result=mysql_query("select * from registered_members where name='" . $_SESSION['name'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $num=mysql_num_rows($result); // print login form and exit if failed. if($num > 0){ header("Location : profile.php?username=$_SESSION['name']"); exit(); }else{ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <div align="center">Please login...<br> <br> </div> <form method=POST action=index.php> <div align="center">username: <input type=text name="name"> password: <input type=password name="password"> <input type=submit value="Login"> </div> </form> <br /> <div align="center"><a href="signup.php">Not Registered? Register now!</a> </div> </body> <?php exit; } ?> </div> Then you design profile.php page as you wish. also I prefer to use the following to lines if($_POST){ $_SESSION['name']=$_POST["name"]; $_SESSION['password']=$_POST["password"]; } just before header coz why you assign sessions if user is putting wrong username/password? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 plz recheck my previous post as I modified it little bit. Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 i tried this code and im getting a error saying .. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\Test\log\inc\auth.php on line 23 any ideas what this is? thanks Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 post code from line20 to line 25 Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 // print login form and exit if failed. if($num > 0){ header("Location : profile.php?username=$_SESSION['name']"); exit(); }else{ line 20 is blank Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 by putting profile.php?username=$_SESSION['name'] as the form action brings up a blank page, am i going in the right direction or not? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 funny problem ... u cant put any space between Location and :, that is if($num > 0){ header("Location: profile.php?username=$_SESSION['name']"); exit(); }else{ more appropriate if($num > 0){ $a=$_SESSION['name']; header("Location: profile.php?username=$a"); exit(); }else{ Quote Link to comment Share on other sites More sharing options...
heirani1 Posted June 20, 2008 Author Share Posted June 20, 2008 thanks abdbuet it works now if i was to create more pages for a user so links from profile.php for each unique user would i do the same thing? or slighty different? thanks again youve been a great help Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 20, 2008 Share Posted June 20, 2008 I dont get ur question exactly. plz clarify a bit more. 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.