We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    If you want to redirect them immediately, it would take a custom snippet. Something like this:

    [[!CheckStatus]]


    <?php
    /* CheckStatus snippet */
    $loggedIn = $modx->user->hasSessionContext($modx->context->get('key'));
    if ( $loggedIn) {
        return '<a style="width:100px;" href="[[~14]]">member link</a>';
    } else {
        $url = $modx->makeUrl(31, "", "", "full");
        $modx->sendRedirect($url);
    }
      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
      • 45950
      • 40 Posts
      I'm trying to create a conditional link that if a member is logged in then they would see member link instead of the sign-up link as well as a conditionall link on generic pages such as help (outside of the members area) that would generate a link back to the member area.

      for testing I put [[+modx.user.id]] on the top of the page to verify the user being logged in or not
      and the call to the IF snippet as:
      [[!If?
      &subject=`[[+modx.user.id]]`
      &operator=`>`
      &operand=`0`
      &then=`<a style="width:100px;" href="[[~14]]">member link</a>`
      &else=`<a style="width:100px;" href="[[~31]]">sign-up</a>`
      ]]
      I've tried this cached and uncached and the only sucess is if I clear the site cache every time.

      The problem I'm having is this:
      If a user logs in and is taken to the clubhouse so to speak, all is well. BUT if they click on a link that leads to generic pages, eg. home page the links in the IF statement do not change and it shows the user being logged out userid=0

      If I refresh the page it then shows the userid, but on logout and returning to the home page still shows a userid but links don't change and clicking on the member link results in a blank page as expected.

      However, I'm still trying to figure out how to make it redirect to the home page if they are not logged in or at the very least a message that tells them they must login or sign-up to access the page. But that's another issue.

      Am I missing soemthing here? Is this the right way to go about getting the result I need?
      Any help would be greatly appreciated... Still a noob but learning...
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You might do better if you used one of the snippets designed for this sort of thing.

        http://modx.com/extras/package/personalize
        http://modx.com/extras/package/membercheck
          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
          • 45950
          • 40 Posts
          Quote from: sottwell at Dec 30, 2013, 04:23 PM
          You might do better if you used one of the snippets designed for this sort of thing.

          http://modx.com/extras/package/personalize
          http://modx.com/extras/package/membercheck

          Much Appreciated! Personalize Does the Trick!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            One of the virtues of great programmers - laziness. If somebody else has already done it, use their stuff wink
              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
              • 45950
              • 40 Posts
              That's how I've managed so far... smiley I'm a designer by trade and if I can find something I need I use it. thus is why I am SOOOO glad I found MODX!