472,988 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,988 software developers and data experts.

Am I online?

I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!
Jul 17 '05 #1
9 2047
David wrote:
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!


Hi David,

The simplest solution is to store a timestamp and a sessionid in that table.
After every request by this user, update the timestap. (updatescript)

Now decide on a reasonable timeout X (30 minutes eg).

Now delete all records that are older than (now - X).
You could use a cronjob, but a simple delete from tblWhoIsOnline where (...)
could do the job too. Just run that Query every time you use the
updatescript.

You probabaly want to put all that code in an include you use on every
php-page.

Good luck,
Erwin Moller
Jul 17 '05 #2
David wrote:
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!


If you wanted to be adventurous you could write your own session
handling functions and store those in the database, not sure how
difficult it is, I have never done it but info is at...
http://uk.php.net/manual/en/function...ve-handler.php

~Cameron
Jul 17 '05 #3
bi****@hotmail.com (David) wrote in message news:<3e**************************@posting.google. com>...
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!


Look at the previous discussions.

- http://groups.google.com/groups?thre...ing.google.com

- http://groups.google.com/groups?thre...ing.google.com

HTH

--
"I don't believe in the God who doesn't give me food, but shows me
heaven!" -- Swami Vivekanandha
Email: rrjanbiah-at-Y!com
Jul 17 '05 #4
What about keeping track of when the user last did something--came
online, viewed a page, etc. Every time someone needs to check the
"online" table you could update the status of everyone who hasn't had
any activity in the last 5 minutes to be "offline."

So it's three steps. First, update a user's last_action_time value
with every new page view. Then with each request to see who's online,
you update everyone's status who hasn't been active lately. Last,
retrieve information about who is actually "active".

Might that work?
MKatz843

bi****@hotmail.com (David) wrote in message news:<3e**************************@posting.google. com>...
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!

Jul 17 '05 #5
I tend to agree with (M. Katz).

After messing around with sessions all night, and using a database to
handle sessions myself I have come to the conclusion that it is
unessasary.

By updating a column "time" in the dbase where the user=currentUser to
time()+ X every time a user loads a new page.

Then having a second script which is executed on every page (or maybe
a cron job) which goes through searching for users whom have their
"time" value > current time then setting their "is_online" attribute
to equal no.

Now I cant see the need for sessionIDs or, limiting the duration of a
session or anything other that what I mentioned!

There must be something wrong with my idea, surely?
Jul 17 '05 #6
I would approach the problem directly. Basically what you want to know is
the users who have an active session. So scan the folder where the PHP
session files are kept--you can obtain the path with a call to
session_save_path(). Open each of them and pass the content to
session_decode() to get the variables in the sessions.

$current_sess_str = session_encode(); // save current session
$active_sessions = array($_SESSION); // add the current session to the
list
$sess_path = session_save_path();
if($dir = opendir($sess_path)) {
while($file = readdir($dir)) {
if(is_file("$sess_path/$file")) {
if($sess_str = @file_get_contents("$sess_path/$file")) {
$_SESSION = array();
session_decode($sess_str);
$active_sessions[] = $_SESSION;
}
}
}
}
$_SESSION = array();
session_decode($current_sess_str); // restore current session

When the session expires or when you call session_destroy(), PHP removes the
session file.

Uzytkownik "David" <bi****@hotmail.com> napisal w wiadomosci
news:3e**************************@posting.google.c om...
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.

When the user clicks to log out, we simply change the state of this
field to no.
The problem comes when a user does not execute the log out script and
simply closes their browser, effectively logging them out.

How can I keep the state of the online attribute accurate? I have had
a few ideas such as using a JavaScript sniffer which detects when the
windows is closed then updates the dbase, however I don't believe such
a jscript exists?

Another possible solution would be to have a cron job but Im not sure
what the cron would check for and I feel there must be a better way
anyway!

Any suggestions welcomed!

Jul 17 '05 #7
"David" <bi****@hotmail.com> wrote in message
news:3e**************************@posting.google.c om...
I am setting up a web community with a feature that will display
whether or not a member is currently online.
I intend on implementing this by holding a column in the dbase simply
called online. When a user logs on, the status of this will be updated
to yes.
.........................
Any suggestions welcomed!


I use a simple db not another table in a db, but one if its own, and I just
update a timestamp [time()] for each user when they load a page.

to see who is online, I run through and list off all those < time limit
I have one of those, idle for 5 minutes, 10min, 15 min, offline type of
things

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #8
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<is********************@comcast.com>...
I would approach the problem directly. Basically what you want to know is
the users who have an active session. So scan the folder where the PHP
session files are kept--you can obtain the path with a call to
session_save_path(). Open each of them and pass the content to
session_decode() to get the variables in the sessions.

$current_sess_str = session_encode(); // save current session
$active_sessions = array($_SESSION); // add the current session to the
list
$sess_path = session_save_path();
if($dir = opendir($sess_path)) {
while($file = readdir($dir)) {
if(is_file("$sess_path/$file")) {
if($sess_str = @file_get_contents("$sess_path/$file")) {
$_SESSION = array();
session_decode($sess_str);
$active_sessions[] = $_SESSION;
}
}
}
}
$_SESSION = array();
session_decode($current_sess_str); // restore current session

When the session expires or when you call session_destroy(), PHP removes the
session file.


This method is still not perfect. See previous discussions
<http://groups.google.com/groups?threadm=abc4d8b8.0311040007.75d45aeb%40post ing.google.com>

AFAIK, in PHP, the best method is to go for custom session handler,
so that you may have more control over the sessions (esp you may
simulate gc, and count guests & users easily).

--
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #9
Regarding this well-known quote, often attributed to David's famous "2 Feb
2004 15:15:57 -0800" speech:
I tend to agree with (M. Katz).

After messing around with sessions all night, and using a database to
handle sessions myself I have come to the conclusion that it is
unessasary.

By updating a column "time" in the dbase where the user=currentUser to
time()+ X every time a user loads a new page.

Then having a second script which is executed on every page (or maybe
a cron job) which goes through searching for users whom have their
"time" value > current time then setting their "is_online" attribute
to equal no.

Now I cant see the need for sessionIDs or, limiting the duration of a
session or anything other that what I mentioned!

There must be something wrong with my idea, surely?


Well, to make it easier on the server processor load, you only really need
to run the "housecleaning" script when someone tries to view an
online/offline status. It's a "tree falls in the woods" situation. If no
one's looking, does that person's status matter?

For that matter, you might not even need to traverse the whole table if
it's just a "My Friends" list. You'd only need to check for expiration on
usernames people were actually trying to look at.

For that matter, you might not even need to have that "expired" entry. Just
have a "LastTimeOnline" column, and say "if LastTimeOnline < now-5, they're
offline". You'd have the added benefit of a "Last Seen" entry, if you ever
wanted it, as well as a smaller table.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mario | last post by:
Hi, I'm experiencing a nasty problem with Visual Studio .Net 2003. Most Online Resources in the Start Page doesnt work, showing the following message: "This feature requires that you have...
2
by: Daniel Orner | last post by:
Is it at all possible to use JavaScript to find out if someone's online or not? E.g. to try and fetch a URL and figure out if it failed or not? I'm trying to add some functionality to my primarily...
16
by: andy.standley | last post by:
Hi, we are running DB2 V8.2 (8.1.0.80) on redhat linux and I am trying to set the reorg to be online. I use the control center on the box - db2cc and then configure automatic maintenance wizard -...
6
by: Raj | last post by:
How can we do an online restore of a tablespace using the incremental backup's? we are on a partitioned database... Also, how could we use backup copy made by the load (using the copy to option...
10
by: Konstantin Andreev | last post by:
Hello. Some time ago I asked in this conference, - How to use an ONLINE BACKUP to restore database onto another system? - but got no answers. Therefore I can conclude it is not possible. But......
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.