Digital Point Forums
iKobo

Go Back   Digital Point Forums > Design & Development > Programming > PHP
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Jan 19th 2008, 1:48 pm
SpyJoe SpyJoe is offline
Peon
 
Join Date: Jan 2008
Posts: 1
SpyJoe is on a distinguished road
PHP: Display data of logged on person

Hi everyone, I'm creating a social network website, like MySpace or Facebook, but a simple one. I used a code I found on a website for login, register and logout. What I'm trying to do now is display member's data (like name, gender, etc) that member has registered with. So just like a profile of someone who is logged in.

This is part of the code that I have already:

php Code:
<?
$conn = mysql_connect("###", "###", "###") or die(mysql_error());
mysql_select_db('###', $conn) or die(mysql_error());

$result = mysql_query("SELECT * FROM users",$conn);
printf("First Name: %s<br>\n", mysql_result($result,0,"firstname"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"lastname"));
printf("Gender: %s<br>\n", mysql_result($result,0,"gender"));
mysql_close($conn);
?>
But this only displays the first row from my database. I need to do something like this:

php Code:
$result = mysql_query("SELECT * FROM users WHERE username=$username",$conn);
I'm not sure if the username of person who is logged in is stored in a cookie or somewhere else, because code is quite complicated.

What do I need to put, so that it displays information of a person who is logged in? Can someone reply asap plz. Thank you!

P.S. Sorry forgot the most important thing. This is where I got the code from:

Code:
http://www.evolt.org/article/comment/17/60265/index.html
Reply With Quote
  #2  
Old Feb 9th 2008, 12:52 pm
barts2108 barts2108 is offline
Peon
 
Join Date: Feb 2008
Location: Netherlands
Posts: 18
barts2108 is on a distinguished road
If you only want to show the username to the logged in user
you can add a session variable to his/her current session

Code:
if (login($_POST['username'],$_POST['password']) == TRUE)
{
	// User logged in. store username in session variables
	session_register("username");
	$_SESSION['username'] = $_POST['username'];
}
Anywhere you want to show the username you can echo it assuming
all your pages have .php extension

example:

<p><?php echo($_SESSION['username']); ?></p>

If you want to show to all users who's online, you must make sure that
active sessions will expire automatically within reasonable time.

Upon login of a user, in the login table you can have a column "loggedin"
and keep track of users who logged in or logged off. If a user not logs
off but the session expires, I am not sure how to handle the loggedin column,
but I hope it gives you an idea
Reply With Quote
  #3  
Old Feb 10th 2008, 5:54 am
Alley Cat Alley Cat is offline
Grunt
 
Join Date: Mar 2007
Location: Lancashire UK
Posts: 38
Alley Cat is on a distinguished road
This is the code that I use to welcome a member to each page that they view.
Code:
if (!isset($_SESSION['first_name'])) {

	$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
	if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
		$url = substr ($url, 0, -1);
	}
	$url .= '/login.php';
	
	ob_end_clean();
	header("Location: $url");
	exit();
	
} else {
	};

echo '<h1>Welcome';
if (isset($_SESSION['first_name'])) {
	echo ", {$_SESSION['first_name']}!";
};
echo '</h1>';
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Data Entry Person harjitgill Services 19 Mar 15th 2009 7:18 am
display the certain data kumar84 PHP 3 Jul 4th 2007 6:53 pm
how to display data from mysql in php luca_p7 PHP 2 Sep 19th 2006 6:23 am
php stay logged in? liam_d PHP 9 Jan 6th 2006 2:23 pm
pulling data from mysql recordset and manipulating its display with php jim_h PHP 2 Nov 13th 2005 8:23 am


All times are GMT -8. The time now is 3:33 pm.