942,959 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 171
  • PHP RSS
Jul 29th, 2010
0

How to tell if a member is online or offline?

Expand Post »
Hai, i'm new to cookies/sessions, so i'm not sure how to do this. So, theres a row in the user account table called 'online'. When their online, the value is 1. When their offline, the value is 0. I'm not sure how to do this, like to store a cookie then remove it when they leave? Halp please
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dartz654 is offline Offline
20 posts
since Jun 2010
Jul 29th, 2010
0
Re: How to tell if a member is online or offline?
If everyone is required to sign-in, then you can update the "online" indicator when they sign in. When they sign out or after they have been inactive for a certain amount of time, you can reset it to "offline". If you can also have active users who aren't signed in (just browsing), then you can also get the total count of active sessions - see the link below:

http://www.olate.co.uk/articles/131
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Jul 30th, 2010
1
Re: How to tell if a member is online or offline?
The simplest way to do this is to make a column to store the last time the user was active. E.g:

php Syntax (Toggle Plain Text)
  1. // Before end of script
  2. $time = time();
  3. mysql_query("UPDATE Members SET last_active='$time' WHERE memberid=$memberid", $con);

Then to check if a user is online or not, choose a window of activity(say, 1 minute).

php Syntax (Toggle Plain Text)
  1. $inactive = bcsub(time(), 60);
  2. $query = "SELECT * FROM Members WHERE last_active > $inactive";
  3. $result = mysql_query($query, $con);

One thing to keep in mind: Some users may not log out, or may just go away from the comp with the window still up, leaving their session active far past when they should really be considered online. Figure out how you want to define an "online" user.
Last edited by Lsmjudoka; Jul 30th, 2010 at 2:53 am.
Reputation Points: 10
Solved Threads: 9
Junior Poster in Training
Lsmjudoka is offline Offline
72 posts
since Apr 2009
Jul 30th, 2010
-1
Re: How to tell if a member is online or offline?
use cookies.
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
raju_boini525 is offline Offline
53 posts
since Aug 2009
Jul 30th, 2010
0
Re: How to tell if a member is online or offline?
You could also override the default session handler, and set it up to instead use a database table to store sessions. A count of the rows in the table will yield your currently active session list.

This also sets you up to be able to use your sessions across multiple servers and gives you the ability to kill all user's logged in sessions for something like maintenance mode etc.

http://www.php.net/manual/en/functio...ve-handler.php
Sponsor
Reputation Points: 265
Solved Threads: 126
Practically a Master Poster
mschroeder is offline Offline
623 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Code to access SQL SERVER 2008 tables
Next Thread in PHP Forum Timeline: Transfer database to SQL server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC