Re: Users Online?
| From: | Michael A. Peters | Date: | Sun, 21 Jun 2009 08:10:19 +0000 |
| Subject: | Re: Users Online? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294378@lists.php.net to get a copy of this message | ||
Paul M Foster wrote:
On Sat, Jun 20, 2009 at 01:33:52PM -0700, Chris Payne wrote: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; +--------------+--------------+------+-----+---------+-------+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.
| 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.