How do most sites handle "is user online?", "# of Online Users" |
[eluser]inktri[/eluser]
Do they just store the user_id along with session data in the session table? Is CodeIgniter's Session library's DB a farely good indicator of online users (ie. does it delete a user's session record within an hour or so of the user's session end?) number of records in session table = number of online users? seeing if a user is online is just a lookup on the session table on user_id Thanks
[eluser]Jamie Rumbelow[/eluser]
What I do is have a "last_seen" field in the users table, set to a PHP time(). When the user views a page, logs in or out, or some other function, we update the field. Then, when we need to find out what users are online, we can "SELECT * FROM users WHERE last_seen = ".time()-300 This means that we select the users that have been active in the last five minutes.
[eluser]sensimevanidus[/eluser]
As far as I know, CodeIgniter's Session Library's db table does not contain a column like "user_id". I guess you gotta implement that on your own or you could use an Auth extension. Take a look here: http://ellislab.com/codeigniter/user-gui...sions.html. In addition, I'd highly recommend cache usage for a feature like this.
[eluser]sikkle[/eluser]
The easy way is just to add a user_id field into ci_session table if you use database session. That will just mean when the user log in, you insert his user id in the userdata indeed, and also in the user_id field. That being said, after you just give a look to active session <= time() - 200. Also to prevent duplication, just do the selection with distinct user_id indeed. good luck ! |
Welcome Guest, Not a member yet? Register Sign In |