We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36752
    • 27 Posts
    Sometimes, on my site, after users have logged in and been directed to a "login success" page, when they attempt to navigate to a secure page they will be given "you must login" messages contingent on !$modx->user->isAuthenticated('web').

    It seemed like they were logged in the first time. From the "login success" page, everything seems to indicate they're logged in (even a logout link displays).

    But as soon as they navigate to the secure page, they are no longer logged in. They must return to the login page to try again. Usually after the second login, they can view the secure content without any problems, and remain logged in until they logout.

    Note: the secure content is not in a resource group. It is only secured via a snippet that checks whether the user is authenticated into the web context.

    If anyone can help, that'd be greatly appreciated. This is a usability nightmare for my users and I don't know how to fix it.

    Using MODX Revolution 2.1.3-pl (traditional)
    Login 1.6.5pl

    This question has been answered by multiple community members. See the first response.

      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: andrewjh at Sep 02, 2011, 09:22 PM
      Note: the secure content is not in a resource group. It is only secured via a snippet that checks whether the user is authenticated into the web context.
      Perhaps you should share the code that is doing this check...
        • 36752
        • 27 Posts
        The following code checks one of the user's extended fields to determine the content on the page, after checking to see if they're logged in and not belonging to a particular user group.

        <?php 
        
        
        	if (!$modx->user->isAuthenticated('web') OR $modx->user->isMember("Students")) {
        	
        	$output = '<p>We\'re sorry, you must be signed in as a parent to view this page. Please login <a href="[[~94]]">here</a>.';
        	return $output;
        	} 
        
            if ($modx->user->isAuthenticated('web') AND $modx->user->isMember("LBParents")) {
        	$offline = "<h2 style=\"color:red\">Sorry, South Campus forms are currently closed.</h2>";
        
            $profile = $modx->user->getOne('Profile');
        	$fields = $profile->get('extended'); 
        
        	$schoolCampus = $fields['schoolCampus'];
        
            if ($schoolCampus == "N") {
            echo ('[[$lunchOrderProgramNC]]');
            }
        if ($schoolCampus == "S") {
          echo ('[[$lunchOrderProgramTop]][[$lunchOrderProgramBottom]]');
        }
        }
          • 36752
          • 27 Posts
          I believe I've narrowed it down a bit:

          If I place a link to the private content on the Login Successful page, users can click that to access the private content without any problems. It authenticates their context just fine.

          But I've also got a weblink to the resource in the top level navigation menu, which seems to cause problems. The first time people login and click the link from the nav menu, the user session reverts to an unauthenticated state.

          Oddly enough, on the second login attempt, clicking the weblink works fine.

          Maybe weblinks are only setup to authenticate properly when user access is limited using resource groups?

          Can someone shed some light on this?
            • 36752
            • 27 Posts
            The problem is still occurring. I honestly don't know what is causing it.

            People simply cannot login sometimes. They login, it says they're logged in, they visit different pages that check their authentication in the web context, and they're suddenly logged out again.

            It seems to be a browser independent issue. Maybe it's a caching problem? The session variable isn't getting cleared or something?

            I'm at my wit's end with this. My site is essentially broken right now, and my entire client base is freaking out. I feel seriously let down. I had high hopes for MODx and in the past it's been really stable. This is completely baffling and is almost enough to turn me off the CMS completely.

            Can no one help me?
              • 22303 MODX Staff
              • 10,725 Posts
              It's very hard to tell what the issue might be without being able to debug your Snippets on the site (i.e. in Context). Have you tried debugging the calls in your Snippet to see why it's not working the first time? Could you be caching something important in the process? You can debug specific pieces of code by using the setDebug() method of the modX class.

              <?php
              /* set debug to true temporarily and store the old value */
              $oldDebug = $modx->setDebug(true);
              if (!$modx->user->isAuthenticated('web') || $modx->user->isMember("Students")) {
                  $output = '<p>We\'re sorry, you must be signed in as a parent to view this page. Please login <a href="[[~94]]">here</a>.';
                  return $output;
              }
              /* return debug to previous value */
              $modx->setDebug($oldDebug);
              


              This will output a lot of information to your core/cache/logs/error.log that you can review as you navigate through the process. Alternatively, you can also redirect the logging output to the page as HTML.
              <?php
              /* set debug and HTML logging temporarily and store the old values */
              $oldDebug = $modx->setDebug(true);
              $oldTarget = $modx->setLogTarget('HTML');
              if (!$modx->user->isAuthenticated('web') || $modx->user->isMember("Students")) {
                  $output = '<p>We\'re sorry, you must be signed in as a parent to view this page. Please login <a href="[[~94]]">here</a>.';
                  return $output;
              }
              /* return debug and logTarget to previous value */
              $modx->setDebug($oldDebug);
              $modx->setLogTarget($oldTarget);
              
                • 36752
                • 27 Posts
                Thank you, I will give that a shot.
                  • 36752
                  • 27 Posts
                  So I ran into an interesting error on the Manager login page. I tried logging in, and it gave me the error $_Session variable not set. I forget the exact wording, but it was along those lines. I logged in a second time, and it worked fine.

                  This seems to correspond to the problems my users have been encountering. Sometimes, on the first login, the session variable is simply not getting set. Is anyone else encountering this problem? Is there any way to fix it?
                    • 3749
                    • 24,544 Posts
                    Do you have Captcha turned on? Captcha saves the correct answer in a $_SESSION variable and returns a "$_SESSION variable not set" error if it's not there when it's time to check the user's input against it.

                      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
                      • 36752
                      • 27 Posts
                      I do have Captcha turned on. That must be what happened. Damn, I was hoping I was getting closer to figuring out the double-login thing. Oh well.

                      Thanks for the response.