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

2k views Asked by At

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?

1

There are 1 answers

0
Johan van den Broek On BEST ANSWER

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();