We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43018
    • 2 Posts
    I'm trying to get sessions working between our MODx site and an external non-MODx system we've created that's running on a subdomain of the domain running MODx. What I've done to attempt this is to set the session_cookie_domain to .example.com and change the session name to the same name for both sites. However, whenever I change the session name to anything other than the default, sessions completely stop working on MODx.

    I'm running both systems on the same CentOS 6.3 server, running PHP 5.3 via mod_php on Apache 2.2.15. The MODx installation is Revo 2.2.5. The session.save_path is set to /var/lib/php/session in the global php.ini, but in the course of setting this up, I have explicitly defined it as such in the .htaccess for both sites to be sure. In order to have the sessions on MODx handle the same as they are on the external system, I've set the session_save_handler to the default PHP file-based system, so there are no entries in the modx_sessions table in the database.

    Initially, I had changed the session_name and session_cookie_domain via site settings, which seemed to work fine on Rackspace's cloud hosting (from which we emigrated due to its inherent incompatibility with MODx), but when we migrated, this ceased working; loading any MODx page would immediately destroy any session on the site (effectively logging the user out of the manager, as well). Changing the session_name setting back to blank resolved the sessions within MODx, but didn't give the necessary crossover functionality between the two systems.

    Failing this, I decided to try and change the $site_sessionname within /core/config/config.inc.php, thinking for some reason that there was perhaps some conflict between the two values that was causing the sessions to not be saved correctly. Having changed this, sessions are now completely broken in MODx regardless of the settings I have in place for them.

    How might I get sessions working again, and -- more importantly -- working between the two systems? I'm not sure what I'm missing, and it's driving me crazy.

    If there's any more information needed from me, I'll be glad to provide it.

    Thanks.
      • 43018
      • 2 Posts
      6 weeks later, and I'm still having trouble with this.

      Here's an overview of the situation:

      There are primarily two different subdomains being utilized with this site. One is the main site running MODx (www.example.com), and the other is a subdomain not running MODx (sub.example.com), but our external system with its own user login system. We'd like to have the user login sessions carry over from sub.example.com to www.example.com, as there are features and quick links that are useful to the user while logged in that we'd like to have available to them as they move between the informational pages of the MODx www.example.com site and the user-oriented system on sub.example.com.

      Both of these subdomains are running on the same CentOS server as specified in my original post. I've modified the session configuration since my original post according to some other forum posts I found regarding utilizing sessions in external scripts (particularly this post: https://forums.modx.com/thread/13645/accessing-modx-session-vars-from-external-scripts#dis-post-75399 by lizardx), yet I still can't seem to get it to work. I can log in with no issues to the external system, yet any attempt to access the session on the MODx site instantly kills the session on both the MODx system and the external user system.

      I've set the session_cookie_domain to .example.com. My external script doesn't call its own session, but instead implements the MODx class and starts a CMS session via the following code:

      if (empty($modx)) {
      	require_once '/var/www/html/www.example.com/web/config.core.php';
      	require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
      	require_once MODX_CORE_PATH.'model/modx/modx.class.php';
      	 
      	$modx = new modX();
      	 
      	$modx->initialize('web');
      }
      


      This code is contained within a PHP script that is called on each page of the external system. The script also contains database connection calls for the external system's database, which is occasionally used on the MODx site, as well. That's why I check for if $modx is empty before require the configuration files and initializing MODx.

      Session variables are simply added to the existing $_SESSION super global once the session has been initiated with this script.

      Could anyone point me in the right direction in terms of getting a session properly carrying over between the two subdomains?

      Thanks again.


      EDIT: Here's some more information. I have the PHP session_name value set to the same for both systems, and I have a test script set up on each subdomain that initializes the MODx session exactly as it is on the external system (the code above). That test script also calls session_id(), session_name(), and print_r($_SESSION). From looking at the output, it appears as though the session name and ID are identical between the two domains, but the contents of the $_SESSION superglobal for the other subdomain get purged whenever $modx->initialize is called. So visiting www.example.com will set up a MODx session with given ID and name, and then visiting sub.example.com will retain that exact name and ID, but simply calling $modx->initialize from that domain will completely empty the $_SESSION superglobal on www.example.com, and vice versa. There are no attempts to write to the $_SESSION, but simply calling it empties it out. [ed. note: yoczechit last edited this post 13 years, 6 months ago.]