Users Online
Note: Read The Comments.
First of all the mySQl query.
Code
ALTER TABLE `members` ADD `online` VARCHAR( 12 ) NULL;
That'll add the field online to the table.
Next you will need to save this file as online.php.
PHP Code
<?php
$logout_time = 300; //mili seconds to stay logged in
$current = time(); //current time
$offline = ($current - $logout_time); //do the math for the logout time
if($logged[username]){ //if they are logged in
$update = mysql_query("UPDATE `members` SET `online` = '$current' WHERE `username` = '$logged[username]';"); //update their status
} //end the check and such
?>
Not much to it really. Just a few variables that will be used for setting users as online and such.
Next you will want to stick this code where you want the users to be displayed.
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
include("online.php"); //get online configuration and such
$get_online_users = mysql_query("SELECT * FROM `members` WHERE `online` >= '$offline' ORDER BY `userlevel` ASC"); //get all online users
$total_users = mysql_num_rows($get_online_users);
if($total_users == 0){ //see if anyone is logged in
echo "No Users Online!"; //there isn't =O
}else{ //maybe....
$i = 1; //the variable 'i' is 1
while($online = mysql_fetch_array($get_online_users)){ //loop online users
if(($i > 0) && ($i != $total_users)){ //see if i is the same or not of total online users
$comma = ', '; //if it isn't then theres a comma
}else{ //or....
$comma = ''; //if there isn't theres no comma
} //end check
echo "<a href='members.php?user=$online[username]'>$online[username]</a>$comma"; //echo the online users with the comma
} //end loop
} //end
?>
Then thats that. If you get any errors please post a comment