Page 1 of 1

Keeping a record on users IDs

Posted: Thu Feb 05, 2004 1:41 pm
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

Posted: Thu Feb 05, 2004 1:50 pm
by Illusionist
look at this thread

Posted: Thu Feb 05, 2004 2:07 pm
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...