We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46132
    • 1 Posts
    Hi everybody.

    I need the list of IDs of the users logged into my web.
    With this code I get the total list of registered users, but I need only logged users.
    Can someone help me with that?

    Sorry for bad english, I'm Spanish user.

    $query = $modx->newQuery('modUser');
    $query->leftJoin('modUserProfile','Profile');
    $query->where(array('id:>' => 2, "Profile.blocked:=" => 0, "active:=" => 1));
    $users = $modx->getCollection('modUser', $query);
    
    foreach($users as $user){
        $modUser        = $user->toArray();
        $profile        = $user->getOne('Profile');
        $modUserProfile = $profile->toArray();
        
        $output.= $modUser['id'].'<br>';
    } 
    
    return $output;
    

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The Login package should have installed a snippet named "ActiveUsers" that should do what you want. I don't have any experience with it personally, nor do I know of any documentation for it.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 46177
        • 3 Posts
        Подскажите пожалуйста что мне делать ? Решил добавить новость на сайт , зашел на главную страницу чтобы изменить новость и у меня исчезло картинка (профиль , шаблон , оглавление я незнаю как еще можно это назвать )
          • 3749
          • 24,544 Posts


          foreach($users as $user){
              $modUser        = $user->toArray();
              $profile        = $user->getOne('Profile');
              $modUserProfile = $profile->toArray();
              if ($user->hasSessionContext('web')) {    
                  $output.= $modUser['id'].'<br>';
              }
          }
            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