Jump to content

once user logged in take them to their own page?


heirani1

Recommended Posts

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...

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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";
     }
}
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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{

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.