szar wrote:
"szar" <no**@nowhere.net> wrote in message
news:Di***************@newssvr22.news.prodigy.com. .. Anyone know a good way to check if someone is signed in, has a session
going, etc.? I could have a signed in field that updates from 'yes' to
'no' when they sign out, but that wouldn't work well when the session times
out or they just close the browser. Thx.
Steve.
BTW, I do have access to cron jobs but nothing else on the server.
Steve.
Hi Steve,
Two solutions,
1) using the filesystemstorage and session.gc_probability
(I don't recommend this)
If you work with sessionstorage on the filesystem (session.save_handler =
files), you could try this:
(It is a bit ugly)
When you create your session, store the name of the sessionfile (often
stored in temp-directory, check your php.ini session.save_path = /tmp) in
some databasetable accompanied with the username.
Check every X minutes the if the filenames stored in the database are still
in the tempdirectory.
If not delete them from your table.
To make this a little more reliable you might consider to change the value
of session.gc_probability to a much higher value (100), but this means of
course your garbagecollection of stale sessionfiles will run every times.
from php.ini
; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_probability = 1
2) Build it yourself
Maybe a better approach would be to:
a) store in a db-table the phpsessid with a username and a timestamp.
b) every time you do something in the session, update the timestamp in the
db for this user.
c) when you need the 'online visitors', just delete old records from the
table, and what is left are possible online users.
I think the second approach is better.
Good luck,
Regards,
Erwin Moller
PS: In Java we have this beautifull HttpSessionBindingListener, but I am not
aware of similar functionality in PHP.