How to Show Connected Users Online

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vkhambalkar
Forum Newbie
Posts: 3
Joined: Thu Nov 04, 2004 4:15 am
Location: India
Contact:

How to Show Connected Users Online

Post 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]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post 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.
vkhambalkar
Forum Newbie
Posts: 3
Joined: Thu Nov 04, 2004 4:15 am
Location: India
Contact:

Post 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
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post 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
vkhambalkar
Forum Newbie
Posts: 3
Joined: Thu Nov 04, 2004 4:15 am
Location: India
Contact:

Post by vkhambalkar »

how to set time out ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply