Keeping a record on users IDs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
James138
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2004 1:41 pm

Keeping a record on users IDs

Post by James138 »

Hello,
I have started creating a system which users need to log in. But im having problems (once the user has logged in) getting the next pages to recognise who has logged in. Does anyone know how I can pass the UserID Information to the next page? Ive been told i have to use sessions. How do I do this?

Thanks
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

look at this thread
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

sessions, or database managment is one of 2 ways to do this.

one way is via the following code :

Code: Select all

<?php
// say we have a database named Bob with a table of Users
//In that table, we have the fields : user, userid, password, loggedin

mysql_connect('localhost','username','password');
mysql_select_db('Bob');

$user = array();
$sql = "Select user from users where logged_in = '1'";
$result = mysql_query($sql) or die(Mysql_error());

while ($row = mysql_fetch_array($result))
{
	$user[] = $row['user'];
}

// now, let's say that we want to display this info on the page :

echo 'The Following Users are Logged on : ';
for($i=0; $i<=count($user); $i++)
{
	echo $user[$i].'<br/>';
}
?>
that's one way at least...
Post Reply