问题
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:
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();
来源:https://stackoverflow.com/questions/5044326/modx-get-session-id-set-by-modx-to-use-in-module