By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,729 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,729 IT Pros & Developers. It's quick & easy.

Who's signed in

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"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.
Jul 17 '05 #2

P: n/a
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.
Jul 17 '05 #3

P: n/a
I use a session variable to hold the users login name - if that var
isn't == "" then someone has signed in - to see who, I just read the
session var.

To determine if they are still online I use a MySQL table called
online and on every web page I make a call to update that table with a
timestamp - each user has a record in the online table so I can tell
who is online based on the timestamp - I use 10 minutes - if the
timestamp is within 10 minutes of now() then I assume they are still
online.

On Thu, 23 Oct 2003 06:11:47 GMT, "szar" <no**@nowhere.net> wrote:
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.


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.