Logging in is easy peasy. All you do is create a session and store the urrent user's ID. Then, in an include file put something like this:
function IsLoggedIn()
{
if($userid>0)
{
return 1;
} else {
return 0;
}
if(IsLoggedIn())
{
$db->query("SELECT * FROM users WHERE id='$userid'");
$thisuser = $db->get_row();
}
And then in the rest of the document if you want to say "Hi, username!" just put this:
if($thisuser) { echo "Hi, you're logged in as " . $thisuser->name; }
And to log somebody in, just set up a session variable called $userid with their ID in.
Another thing I like alot is the "who's online" bit. That is also very easy. Put this at the beginning of the script:
/* clean out any entries older than 5 minutes or form us */
$cutoff = time() - (60*5); // or is it date()? can't remember
$sql = "DELETE * FROM activeusers WHERE lastvisit < $cutoff OR ip = '$userip'";
$db->query($sql);
/* add our entry */
$sql = "INSERT INTO activeusers(userid, ip, lastvisit) VALUES ('$userid', '$userid', '" . time() . "'";
$db->query($sql);
And then to display the users online just join the activeusers table with the users table and show results