We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53376
    • 32 Posts
    At first I used this:
    $modx->user->hasSessionContext('mgr')

    and it return me false.

    Then I used this construction in my snippet:
    return var_dump($modx->getUser()->get('username'));

    which return me this:
    string(11) "(anonymous)"


    I authorized in manager context (mgr), but in my session I see only this:
    array(2) { ["joomla"]=> string(2564) "TzoyNDoiSm9vbWxhXFJlZ2lzdHJ5XFJlZ2lzdHJ5IjozOntzOjc6IgAqAGRhdGEiO086ODoic3RkQ2xhc3MiOjE6e3M6OToiX19kZWZhdWx0IjtPOjg6InN0ZENsYXNzIjo0OntzOjc6InNlc3Npb24iO086ODoic3RkQ2xhc3MiOjQ6e3M6NzoiY291bnRlciI7aTo5MztzOjU6InRpbWVyIjtPOjg6InN0ZENsYXNzIjozOntzOjU6InN0YXJ0IjtpOjE0OTk2MDY4NTU7czo0OiJsYXN0IjtpOjE0OTk2MTUzNTc7czozOiJub3ciO2k6MTQ5OTYxNTM5MDt9czo2OiJjbGllbnQiO086ODoic3RkQ2xhc3MiOjE6e3M6OToiZm9yd2FyZGVkIjtzOjE0OiIxMjguNzIuMjE5LjE5MSI7fXM6NToidG9rZW4iO3M6MzI6ImhycUFBY08yT3poaHlKTmhrb01uMGhIQlNxckxHczFOIjt9czo4OiJyZWdpc3RyeSI7TzoyNDoiSm9vbWxhXFJlZ2lzdHJ5XFJlZ2lzdHJ5IjozOntzOjc6IgAqAGRhdGEiO086ODoic3RkQ2xhc3MiOjE6e3M6MTA6ImNvbV9rdW5lbmEiO086ODoic3RkQ2xhc3MiOjI6e3M6MTM6InVzZXI1MTI1X3JlYWQiO2E6MTA3OntpOjE4O2k6MTg7aTo2MDtpOjYwO2k6MzY7aTozNjtpOjM3O2k6Mzc7aToyNDtpOjI0O2k6OTtpOjk7aTo4NTtpOjg1O2k6MTE4O2k6MTE4O2k6Mzk7aTozOTtpOjE2O2k6MTY7aToxNDM7aToxNDM7aTo2NDtpOjY0O2k6MTE3O2k6MTE3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OTtpOjEwOTtpOjEyNTtpOjEyNTtpOjExMDtpOjExMDtpOjcwO2k6NzA7aToxMTY7aToxMTY7aToxMzE7aToxMzE7aTo3NztpOjc3O2k6MTIzO2k6MTIzO2k6MTExO2k6MTExO2k6Nzg7aTo3ODtpOjExMjtpOjExMjtpOjExNTtpOjExNTtpOjc5O2k6Nzk7aTo4MDtpOjgwO2k6ODE7aTo4MTtpOjgyO2k6ODI7aTo5MjtpOjkyO2k6OTM7aTo5MztpOjk3O2k6OTc7aTo5ODtpOjk4O31zOjU6InRvcGljIjtPOjg6InN0ZENsYXNzIjoxOntzOjc6Imxhc3RoaXQiO2k6Mzc1O319fXM6MTQ6IgAqAGluaXRpYWxpemVkIjtiOjA7czo5OiJzZXBhcmF0b3IiO3M6MToiLiI7fXM6NDoidXNlciI7Tzo1OiJKVXNlciI6MTp7czoyOiJpZCI7czo0OiI1MTI1Ijt9czoxNjoiam9tc29jaWFsX3VzZXJpcCI7czoxNDoiMTI4LjcyLjIxOS4xOTEiO319czoxNDoiACoAaW5pdGlhbGl6ZWQiO2I6MDtzOjk6InNlcGFyYXRvciI7czoxOiIuIjt9" ["modx.user.contextTokens"]=> array(0) { } }


    Just one MODX key! Where is another?

    I watched session on my other MODX site and it's looks like this:
    array(6) { ["modx.user.contextTokens"]=> array(1) { ["mgr"]=> int(1) } ["modx.user.0.resourceGroups"]=> array(1) { ["web"]=> array(0) { } } ["modx.user.0.attributes"]=> array(1) { ["web"]=> array(5) { ["modAccessContext"]=> array(2) { ["en"]=> array(1) { [0]=> array(3) { ["principal"]=> int(0) ["authority"]=> string(1) "0" ["policy"]=> array(1) { ["load"]=> bool(true) } } } ["web"]=> array(1) { [0]=> array(3) { ["principal"]=> int(0) ["authority"]=> string(1) "0" ["policy"]=> array(1) { ["load"]=> bool(true) } } } } ["modAccessResourceGroup"]=> array(0) { } ["modAccessCategory"]=> array(0) { } ["sources.modAccessMediaSource"]=> array(0) { } ["modAccessNamespace"]=> array(0) { } } } ["modx.mgr.user.token"]=> string(52) "modxXXXXXaff52c861.3820XXXX_1596XXXXX2e4f92.41XXXX97" ["modx.mgr.session.cookie.lifetime"]=> int(604800) ["modx.mgr.user.config"]=> array(0) { } }


    How to solve it?
      • 53376
      • 32 Posts
      I'm authorized but there are no entries in session about this... How?

      My user name is anonimous instead of admin
        • 3749
        • 24,544 Posts
        I'm not completely clear on what you're asking, but when you are viewing the front end of the site while logged into the Manager, you have a very unusual status. You have a session context for the Manager, but you are not logged into the front end. At the same time, you usually have the right to view unpublished documents, but because you are not logged in to the front end, you are the (anonymous) user there.

        If you want to view the front-end as a real visitor would, use another browser where you're not logged into the Manager (or log out of the Manager). Log in to the front end using the Login snippet. Then these will work as expected:

        $modx->user->get('username'); // will return the actual username
        
        $modx->context->get('key'); // will return 'web' (or other front-end context)
        
        $modx->user->hasSessionContext($modx->context->get('key')); // will report login status (true or false)




          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
          • 53376
          • 32 Posts
          Quote from: BobRay at Jul 10, 2017, 04:56 AM
          I'm not completely clear on what you're asking, but when you are viewing the front end of the site while logged into the Manager, you have a very unusual status. You have a session context for the Manager, but you are not logged into the front end. At the same time, you usually have the right to view unpublished documents, but because you are not logged in to the front end, you are the (anonymous) user there.

          If you want to view the front-end as a real visitor would, use another browser where you're not logged into the Manager (or log out of the Manager). Log in to the front end using the Login snippet. Then these will work as expected:

          $modx->user->get('username'); // will return the actual username
          
          $modx->context->get('key'); // will return 'web' (or other front-end context)
          
          $modx->user->hasSessionContext($modx->context->get('key')); // will report login status (true or false)





          You're right, but whis methods returns nothing for me. And I want fix it. Getting username returns me anonymous, getting has session context always returns me false. At first side I logged in manager (I can go through it and to what I want), but at second side I have no any records about I logged inside $_SESSION. How?
            • 3749
            • 24,544 Posts
            If you're losing the $_SESSION it may be because of a change in the domain. If the user comes in in www.yoursite.com but gets switched to yoursite.com (or vice versa), the session will be lost.

            If that's what's happening, uncomment one of the sections (but not both) in .htaccess that forces www or non-www URLs.

              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
              • 53376
              • 32 Posts
              I have just one domain without www
                • 3749
                • 24,544 Posts
                When you watch the browser's address bar, do you ever see www as you navigate from page to page?
                  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
                  • 53376
                  • 32 Posts
                    • 3749
                    • 24,544 Posts
                    It looks like maybe Joomla is starting a new session, which would eliminate the MODX session.

                    Does the domain name change when switching back and forth between Joomla and MODX?

                    There could also be an issue with the way you're instantiating MODX or the time that you're doing 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
                      • 53376
                      • 32 Posts
                      Quote from: BobRay at Jul 15, 2017, 08:51 PM
                      It looks like maybe Joomla is starting a new session, which would eliminate the MODX session.

                      Does the domain name change when switching back and forth between Joomla and MODX?

                      There could also be an issue with the way you're instantiating MODX or the time that you're doing it.

                      I think too about Joomla rewrites my session. I have all on just one single domain, including MODX as Joomla component with URL http://joomla.site/cabinet/ (Base URL is /cabinet/)