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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.