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.

Best Practice for Generating a List of Logged In Members

June 26, 2012 11:27am

Subscribe [1]
  • #1 / Jun 26, 2012 11:27am

    JohnD

    114 posts

    I asked this question in the development forum, but received no responses - hope it’s OK to repost here - could really do with some help on this

    I am developing a module for EE and need some advice re the best practice method for getting the member ids for all logged in members.

    I am asking because I am unsure whether I can always rely on the sessions table, or do I need to check cookies as well.

    Whatever the case, I need to reliably and accurately generate a list of all currently logged in users.

    A related question - when do the entries in the sessions table get removed. I am seeing duplication of members in the sessions table on my development system. This is probably due my still debugging the module, but I am not doing anything to place entries in the sessions table, so they must be left over from sessions that were abandoned. I assume that EE has some kind of garbage collection for this - or not?

  • #2 / Jun 27, 2012 12:51am

    Bhashkar Yadav

    727 posts

    Hi JohnD,

    You can use the below code to find out the online members :

    $time_limit = 15; // Number of minutes to track users
    
    $cutoff = $this->EE->localize->now - ($time_limit * 60);
    
    $this->EE->db->select('member_id, name');
    $this->EE->db->where('site_id', $this->EE->config->item('site_id'));
    $this->EE->db->where('date >', $cutoff);
    $this->EE->db->order_by('name');
    $query = $this->EE->db->get('online_users');

    I copied this code Stats library and did a little change for you. So please look into Stats library.

    I hope, it would help you.


    Best Regards,
    Bhashkar yadav

  • #3 / Jun 27, 2012 6:38am

    JohnD

    114 posts

    Hi Bhashkar, thank you for your suggestion.

    I am not convinced that this method is reliable. It relies entirely on the contents of the online users table.

    This table’s content is subject to the “‘enable_online_user_tracking”  and the “disable_all_tracking” settings, which means that some online members may not be recorded there.

    The purposes of my module require me to reliably have a list of ALL logged in members at any given moment, because my module is affected by the privileges that different logged in users have.

    Any other suggestions?

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

ExpressionEngine News!

#eecms, #events, #releases