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

    How can i tell if a user is logged in or not?

    Something like:

    if ( $isloggedin )
       echo 'You are a logged in user';
    else
       echo 'You are not a logged in user';
    

      • 33337
      • 3,975 Posts
      Zaigham (aka zi) Reply #2, 18 years ago
      There are 2, [[membercheck]] and [[Personalize]] snippets in the default install for this kind of work.

      Hope that helps.

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • Garry Nutting Reply #3, 18 years ago
        For a programmatic check, you could use:
        if ( $modx->getLoginUserType == '' ) {
           echo 'You are not a logged in user';
        } else {
           echo 'You are a logged in user';
        }


        The $modx->getLoginUserType returns 3 possible values: ’web’ for a logged in web user, ’manager’ for a logged in Manager user, and ’’ for a non-logged in user.

        Hope that helps, Garry
          Garry Nutting
          Senior Developer
          MODX, LLC

          Email: [email protected]
          Twitter: @garryn
          Web: modx.com
        • This function will only return "web" if it is being called from the front-end and a web user is logged in; it will only return "manager" if it is being called from the back-end and a manager user is logged in. It cannot be used to determine if a user is logged in as a manager user from a snippet in the front-end.

            function getLoginUserType(){
              if($this->isFrontend() && isset($_SESSION['webValidated'])) {
                return 'web';
              }
              else if($this->isBackend() && isset($_SESSION['mgrValidated'])) {
                return 'manager';
              }
              else return '';
            }
          
            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