We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21120
    • 30 Posts
    I’m trying to get an array of currently logged in users.

    I tried a getCollection() on modSession but i can’t figure out the data.

    is there an easy way to accomplish this?
      • 3749
      • 24,544 Posts
      This will get users active in the last 20 minutes:

      <?php
      $timetocheck = (time()-(60*20))+$serverOffset;
      $c = $modx->newQuery('modActiveUser');
      $c->where(array('lasthit:>' => $timetocheck));
      $c->sortby($modx->getSelectColumns('modActiveUser','modActiveUser','',array('username')),'ASC');
      $ausers = $modx->getCollection('modActiveUser',$c);
      
      foreach($ausers as $auser) {
        $output .= $auser->get('username');
      }
      return $output;

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36493
        • 64 Posts
        I can’t answer you question but I’m guessing the answer would be available from the peoples add-on

        I would check out the Peoples snippet:
        http://rtfm.modx.com/display/ADDON/Peoples.Peoples


        edit: or just use BobRays example grin
        cheers,
          |
          • 21120
          • 30 Posts
          Actually - I tried it, and it’s not exactly working.... the active users table only updates for manager users. is that the expected behavior for the modActiveUser class?

          I should also mention that i’ve extended the modUser class.... could that be causing problems?
            • 3749
            • 24,544 Posts
            Quote from: neilness at Nov 15, 2010, 09:48 PM

            Actually - I tried it, and it’s not exactly working.... the active users table only updates for manager users. is that the expected behavior for the modActiveUser class?

            I should also mention that i’ve extended the modUser class.... could that be causing problems?

            It may only work for Manager users. I don’t think extending modUser would be an issue.

            You may have to add a plugin that listens to the login and logout events and saves the usernames somewhere (e.g., a file or custom db table) -- unless someone else has a better idea.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting