Check who is log in

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I need to write application which tell me
who is login. In example:
1. login as Shamrock
2. I see Shamrock login
3. someone login as Morbious
4. They both see : Shamrock & Morbious
5. Shamrock logout
6. Morbious refresh site and see only Morbious is logged
Any sugesstions ?

Best regards,


Re: Check who is log in

from Shamrock contained the following:

Quoted text here. Click to load it

You need to store the login information in a file or database.  Change
the database when someone logs out (or after n minutes of inactivity).
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs /

[FAQ] Find logged in users

Q: How to find the logged in users?
Q: How to find the number of logged in users?

A: If you use session based authentication/login mechanism, it is quite
easy when you use custom-DB-based session--so that the session
variables will be stored in database instead of default files. As the
session will be available in the database table, it is easy to query
it/count the number of sessions or records.


@todo Cleanup. Better link to DB handler

Re: Check who is log in

Quoted text here. Click to load it

A very simple way to do this is to glob the session save path, obtainable
through ini_get(). Session files have names of the form "sess_<session_id>".
Cut off the prefix and load each session by calling session_id(),
session_start(), and session_write_close(). Be sure to save a copy of the
current $_SESSION first.

The downside to this method is that on a share server, you will end up
reading the sessions of other web sites as well. There are ways to get
around the problem though.

Re: Check who is log in

Quoted text here. Click to load it

Browsers don't log out.  Users rarely log out (if you provide a
link to log out and the login is protecting sufficiently sensitive
information, a few of your users MIGHT use it).

The closest you can usually get is to (a) decide that a person is
logged out if the last page refresh is older than X time, and (b)
process explicit logouts if someone actually uses them.

Put the login info in a database.  If they refresh a page, update
the last_refreshed_timestamp.  To see who is logged in, select the
entries with a login name and whose last_refreshed_timestamp is
later than, say, an hour ago.

                        Gordon L. Burditt

Site Timeline