ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How do most sites handle "is user online?", "# of Online Users"

October 11, 2008 11:54pm

Subscribe [3]
  • #1 / Oct 11, 2008 11:54pm

    inktri

    11 posts

    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

  • #2 / Oct 12, 2008 6:13am

    Jamie Rumbelow

    546 posts

    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.

  • #3 / Oct 12, 2008 3:04pm

    sensimevanidus

    7 posts

    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-guide/libraries/sessions.html.

    In addition, I’d highly recommend cache usage for a feature like this.

  • #4 / Oct 13, 2008 9:29am

    sikkle

    325 posts

    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 !

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases