Jump to content

[SOLVED] Suggestions for displaying whether a user is online/offline?


LooieENG

Recommended Posts

*i already typed this while btherl posted so this maybe unrelated advice

 

 

Create a table, when the user logs in you insert a records, and update its timestamp when they perform actions, for the whos online you check the database for records with a timestamp no later than erm.. 15 minutes..

 

make sense

 

 

With MYSQL I would have a cell called lastaction and then everytime they click have it update to the current time. Then when you want to show them as online or offline have it compare the lastaction time to like time()-600 for within 10mins.

Well, I'm trying to make a forum, and I have an idea for how I can make everything work (adding threads, posts, etc.) but I'm not sure how to set a user's status to online/offline.

 

PHP 5.2.5 and MySQL 5.0.45

 

Edit: Ah, yeah. I should've thought of that  :-[.

 

Thanks everyone.

Whenever a user clicks

 

$time = time();
mysql_query("UPDATE users SET lastaction='$time' WHERE username='$username'");

 

Then when you check to see if they are on or off

 

$s = mysql_query("SELECT lastaction FROM users WHERE username='$username'");
while($r = $mysql_fetch_row($s)){
    $last = $r[0];
}

$range = time()-600;
if($range < $last){
    echo "User is online!";
} else {
    echo "User is offline!";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.