Re: Users Online?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul M Foster wrote:
On Sat, Jun 20, 2009 at 01:33:52PM -0700, Chris Payne wrote:

Hi everyone,

I have a login system that allows a user to login to my control panel,
is there an easy way so that I can tell how many users / what users
are logged into my system?  What would I need to do to add this with
the minimum of hassle?  Would I just have to look at the sessions that
are currently active and if so, how?  I really want to add this
feature as it will help with creating a messaging system.

Doing this purely with sessions is impossible (well, nearly), since
sessions can't see each other.

Yeah - what I do, and why I mentioned database, my session database has a field for userid so that I can easily with a single query associate a userid with a session.

mysql> describe php_sessions;
+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| session_id   | varchar(32)  | NO   | PRI |         |       |
| session_data | longtext     | YES  |     | NULL    |       |
| dt_created   | int(11)      | NO   |     | 0       |       |
| ip_created   | varchar(32)  | NO   |     |         |       |
| dt_modified  | int(11)      | NO   |     | 0       |       |
| ip_modified  | varchar(32)  | NO   |     |         |       |
| userid       | mediumint(9) | NO   |     | 0       |       |
| expires      | int(11)      | NO   |     | 0       |       |
| expired      | tinyint(4)   | NO   |     | 0       |       |
+--------------+--------------+------+-----+---------+-------+

That's one of the advantages to using a database for sessions - you can tie all kinds of groovy information to the session_id that can then help with future forensics and stuff if needed, and instead of deleting a session when it expires, set the expired field so that you can keep expired sessions around for longer yet they aren't useable by a client.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux