szar wrote:
"szar" <no**@nowhere.n et> wrote in message
news:Di******** *******@newssvr 22.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 filesystemstora ge and session.gc_prob ability
(I don't recommend this)
If you work with sessionstorage on the filesystem (session.save_h andler =
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_pa th = /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_prob ability to a much higher value (100), but this means of
course your garbagecollecti on 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_prob ability = 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 HttpSessionBind ingListener, but I am not
aware of similar functionality in PHP.