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

    I'm having a little issue trying to use hasSessionContext.
    I'm looking for a function that tells me if the user is logged in in the front end only. I have only one context, the web default one.
    The problem is that hasSessionContext always returns true tu me. Whether logged in in the front end, back end, or not at all.

    Here's the code i wrote to test it :

    $isAuthenticated = $modx->user->hasSessionContext('web');
    if($isAuthenticated = true)
    {
    return "Logged In";
    }
    else
    {
    return "Off";
    }

    As it souldn't be a real issue for those who are used to this function, please answer soon wink
    Thanks a lot [ed. note: duk3fy last edited this post 15 years ago.]
      • 22303 MODX Staff
      • 10,725 Posts
      You have a mistake in your PHP code; you are assigning $isAuthenticated the value of true inside the if() statement. I think you meant:
      if ($isAuthenticated == true)
      (note the two equal signs that compares rather than assigning the value of true)

      Your code, when corrected works as expected:
      <?php
      $isAuthenticated = $modx->user->hasSessionContext('web');
      if($isAuthenticated == true)
      {
      return "Logged In";
      }
      else
      {
      return "Off";
      }