Page 1 of 1

How to Show Connected Users Online

Posted: Thu Nov 04, 2004 4:24 am
by vkhambalkar
I am able to show connecte users online, separate table is there to kept the record of connected user, whenever users login i am making his online flag='Y', similarly wherenever he gets logout by clicking logout link, online flag becomes "N'. But wherenever someone closes hiw browser without clicking logut link he still show in connected user list, Anyone know how to do this ?

?>[/google]

Posted: Thu Nov 04, 2004 4:39 am
by CoderGoblin
Normally people have a timeout value where if no update (page refresh/page load is used) then people are automatically logged out. If a page on your site is loaded the timeout counter is reset back.

Posted: Thu Nov 04, 2004 4:42 am
by Dr Evil
I check the activity of all users (anonymous and registered) and each time one user calls a page I log this in a table. As I log it I check I f any of those logas are older than for example 5 min. If so I delete them. Then I show all the different users (by IP for number and for anonymous and by username for registered). Each user interaction updates the db.

This can be a bit ressourceful.

Posted: Thu Nov 04, 2004 5:02 am
by vkhambalkar
i am using Unload event to open php page in which update is written to make online flag='N' & whenver new page from the same site is get loaded i have written update statement which again make online flag "Y". i works but sometimes create problem

Posted: Thu Nov 04, 2004 5:42 am
by dreamline
I do the same, i update the users online table on every page, and have a timeout if someone is inactive for about 2 mins... Unless that person refreshes a page within 2 minutes, he becomes inactive.. :D Maybe 2 minutes is a bit short, but it works like a charm.. :D

Posted: Thu Nov 04, 2004 5:45 am
by vkhambalkar
how to set time out ?

Posted: Thu Nov 04, 2004 7:26 am
by timvw
i use sessions... and then i just iterate over the files that exist in my session.save_path directory to count the online users...

Posted: Thu Nov 04, 2004 9:07 am
by CoderGoblin
vkhambalkar wrote:i am using Unload event to open php page in which update is written to make online flag='N' & whenver new page from the same site is get loaded i have written update statement which again make online flag "Y". i works but sometimes create problem
The trouble with this method is what happens when the browser javascript is disabled. I would go for the session/timeout solution.

Posted: Thu Nov 04, 2004 11:26 am
by pickle
I think the simplest thing to do would be to just have 2 values in the connected table - the id, and a timestamp. Everytime a person loads a page, update their timestamp in the connected table. Then, those users online are only those whose stamp is updated in the last 10, 20, 30, however many minutes. This will, however, create a bunch of overhead as there is an additional database call for each page load.