Jump to content

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


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!";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.