Search code examples
phpcontent-management-systemmodxmodx-evolution

MODx :: Get Session ID set by MODx to use in Module


I have an issue where I need to pass the Session ID to a module, "SMF Connector".

The problem stems from the fact that for some reason the SMF Forum (held in a sub-folder) is using a different Session set. I combatted the problem by hard coding the Session ID from MODx, but of course this then failed the next time I loaded up the site a day later.

I have tried using

global $modx;  
$SID = $modx->documentObject[SID];
session_id($SID);
session_start();

But to no avail, infact it was stopping the entire forum from loading!

Any ideas?


Solution

  • The reason is that modx session data is limited to index.php and scripts included from there. I suppose this is by design.

    From what I gather, your SMF script is invoked by a seperate request. Try adding the following lines at the start of your external php script:

    // start MODx session to access its session data
    require_once ($_SERVER["DOCUMENT_ROOT"] . '/manager/includes/config.inc.php');
    startCMSSession();