|
Posted by Ben on 09/14/05 04:33
bruce wrote:
> my question is still how do i determine for a given session, that a user is
> still on the site, or that the user is no longer on the site/system. i don't
> see an automated/system way of doing this.
The web is stateless... There is no automated/system way of doing this.
You know the last time a user requested a file, that's it. It's up to
you to determine what's a reasonable timeout between page requests so
that you can determine when someone has gone elsewhere.
> it appears that i might have to capture the session vars in a db, along with
> the associated time creation. it then appears that i'm going to have to have
> some way of continually updating the session 'time' to reflect that the user
> is still on the system/site. this kind of approach could be done via some
> include file for every page that the user hits on the site. i could then
> trigger off this to determine who's live/on the site.
You can keep doing your session variables however you're currently doing
them, just store a timestamp for each user in a db or file and update it
every time the user requests a file.
Your script that tells you how many users are online can then check
against the db/file and count the timestamps less than $timeout seconds
old, which will be your "users online". The script should also do
garbage collection for any entries with timestamps older than your $timeout.
> the downside to this is that i could kill someone who might be on the
> system, but just not actively using the site.. maybe they stepped away...
So have $extended_timeout which is a ridiculously long time out period
during which users are marked as stale, but not deleted. If they
request a file during the $extended_timeout you start counting them
again, if they don't then after the $extended_timeout they are deleted.
> now, if there was/is away to examine the session var that i store using the
> session handler, such that i could determine which session var is still
> alaive.. then that would solve my issues!!!!
Not really... Sessions are no more or less likely to be accurate for
counting users on your site than what I've described above. They too
time out after a period of time (set in php.ini) and are then subject to
garbage collection. They hang around long after the user.
>
> however, as i've stated, i can't find any code sample/articles that get to
> this point..
>
> any code/thoughts/comments/etc...
Most forums have some type of "who is online" functionality, have a look
at how they do it.
- Ben
Navigation:
[Reply to this message]
|