Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 150
0 Users 2 Guests Online

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
1
2
3
4
5
6
7
8
9
<?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
ShadowMage
Author:
Views:
2869
Rating:
Posted on Tuesday 16th September 2008 at 12:07 PM
jambomb
jambomb
where ??
Posted on Sunday 31st August 2008 at 08:17 PM
dtnet
dtnet
have you used this at the top of the document:

<? include('config.php'); ?>
Posted on Sunday 31st August 2008 at 06:47 PM
jambomb
jambomb
what ?
Posted on Friday 29th August 2008 at 06:04 PM
Dava
Dava
have u included the config file so it can connect to your database
Posted on Friday 29th August 2008 at 01:28 PM
jambomb
jambomb
Would be nice if u show s the links or sumin ?
Posted on Friday 29th August 2008 at 02:12 AM
Dava
Dava
that is 2 basic if you read around u will find it out i have images indicating online and offline status all over my board :)
Posted on Tuesday 26th August 2008 at 02:04 PM
jambomb
jambomb
come on guys..
Posted on Monday 18th August 2008 at 08:13 PM
jambomb
jambomb
Wish some 1 could make that lol
Posted on Monday 18th August 2008 at 05:53 PM
UrbanTwitch
UrbanTwitch
yes
Posted on Monday 18th August 2008 at 04:15 PM
jambomb
jambomb
?