I am trying to enable my web site to display all the logged in users.
I have managed to come up with a script which displays this message: You are logged in as Mark. But I haven't managed to make a message like: Other users are : Clark, David .....
Can somebody help me how to do this based upon my script below:
- File 1 : login.php - Log in page
</table>
<form method=post action="welcome.php">
<table>
<tr><td>username:</td>
<td><input type=text name=userid></td></tr>
<tr><td>Password:</td>
<td><input type=password name=password></td></tr>
<tr><td colspan=2 align=center>
<td> <input type=submit value="Log in"></td></tr>
<br>
</tr>
<tr>
<td><br> <A HREF="new_member.php">new member? </A></td>
</tr>
</table></form>
- File 2 : welcome.php - The welcomepage
<?
session_start();
if ($userid && $password)
{
// if the user has just tried to log in
$db_conn = mysql_connect("localhost", "", "");
mysql_select_db("auth", $db_conn);
$query = "select * from auth "
."where name='$userid' "
." and pass='$password'";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $userid;
session_register("valid_user");
}
}
?>
<html>
<body>
<h3>Welcome</h3>
<?
if (session_is_registered("valid_user"))
{
echo "<font color=blue><b>You are logged in as: $valid_user </font></b><br>";
}
else
{
echo "Not logged in.";
Return;
}
?>
Table name: auth
name_id int unsigned auto_increment primary key
name char(35)
pass char(35)
Thanks for any help.