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

    i used to reference the $_SESSION to identify which user is logged in. Apparently though, it is only available when a manager is logged-in and not on ordinary user type. I used to use webInternalKey of $_SESSION.

    Are there other methods to use to identify which web user is currently active?

    jun
      • 33480
      • 27 Posts
      I was able to identify the fault:

      $_SESSION is not cleared after all.

      I had two different users logged in at the same time: manager on /manager, webuser on front end. When I logged out from /manager, all SESSION data were erased including those of the webuser. Relogging the webuser restores the SESSION data due him.

      grin
        • 21257 MODX Staff
        • 730 Posts
        I recently had a need to include some user data in a template. I used the following code to turn all of the attributes of the current user into placeholders.
        This goes inside a snippet:
        // set web user details as placeholders
        $user = $modx->userLoggedIn();
        $user_details = $modx->getWebUserInfo($user['id']);
        $modx->toPlaceholders($user_details, 'user!');
        

        The first line gets a few details about the logged in user, I’m using the API function userLoggedIn() just to get the user’s id.
        Then on line 2, an array of the user’s data is retrieved using another API function, getWebUserInfo().
        On the third line, I make the user’s record available as a set of placeholders, all prefixed with "user!". This is arbitrary, I could have used a prefix of "eggs_".
        When the snippet is included on a page, then you can put placeholders like [+user!email+] or [+user!fullname+].
        This is not the most secure or tested code.. for entertainment purposes only ;-)
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 33480
          • 27 Posts
          Thanks for the tip, will try it. smiley