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.]