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

    I have a subdomain, managed by GatewayManager, to which I have added a system setting,
    session_cookie_domain 


    However, the context is disregarding (it seems) the system setting, and setting cookies as if they were from the default system settings.

    Does anyone have any ideas why this might be happening?

      • 22303 MODX Staff
      • 10,725 Posts
      The problem is that gateway manager is a plugin and has to switch to a context, but the session is always loaded by the default context loaded in the index.php (web). In order to use a different session for your subdomain, you would need to modify the index.php and have it handle the initialization of the correct subdomain context in the first place.
        • 37514
        • 178 Posts
        Thanks @opengeek!
          • 47802
          • 1 Posts
          Hi,

          Thanks opengeek. Could I check that this sort of thing is what you had in mind for the edit of index.php?

          To replace the section

          /* Initialize the default 'web' context */
          $modx->initialize('web');


          with something like:

          $requestdomain = strtolower ($_SERVER['SERVER_NAME']);
          //switch context for alt.domain.tld to make cookies work properly
          if ($requestdomain == 'alt.domain.tld') {
            $modx->initialize('altweb');
            }
          else {
            //use default context for everything else
            $modx->initialize('web');
            }


            • 37514
            • 178 Posts
            OK, so if we have to rewrite index.php to run subdomains isn't that a bit sub-optimal? It'll make upgrading troublesome for instance.

            Re-reading the manual it seems necessary to modify index.php in order to serve *any* set of domains from the same root; else we should set up multiple roots with custom index.php scripts. The problems that people may encounter with cookies aren't documented in the manual pages, nor for the Gateway Manager pages. But I suspect most people will opt for the one-root-for-all-domains model, because it is much easier on the face of it.

            Wouldn't it be better for the MODX index.php script to be able to pick up what context it ought to be serving "out of the box"?