Number of Online User Problem

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
fadi
Forum Newbie
Posts: 10
Joined: Wed Mar 24, 2004 1:26 am
Location: Asia:Pakistan

Number of Online User Problem

Post by fadi »

Hi Folks,
i've recently made a script which tells the exact number of online users on my website. Method i am using is following
1. i ask username and password
2. if matches in database than insert in another table
3. On Sign Out i delete that user.
it works fine as far as it is concerned with sign out.

but i dont have any solution if user clicks the Cross button of browser and session is lost .But infact i cant delete that user from table. Is there any way to sort out this problem , plz help 8O
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

The best way to do this (and there are a ton of post on this site about this) is to put an insert/update query in every page. After x amount of time (5 - 10 minutes) Assume the user is no longer there and do not display them as being there. There are a couple ways to do this. one way is to run a cron job that removes all entries older then x minutes. another is to just write your quiery to only count those that are <= x minutes old.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

search for "who online"
Post Reply