Session Variables

Accessing session variables from non-MODx resources

Sometimes, it is necessary for a non-MODx managed application to gain access to the session variable space used by MODx.

One example of such a situation would be a PHP application that generates JPEG 'Captcha' images, where the real text of the Captcha needs to be placed in MODx's session space for subsequent verification.

The following code inside a PHP application will initialise MODx so that the correct session space is accessed:

// Include files to declare the MODx core class
require_once '/path_to_your/config.core.php';  
require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';  
require_once MODX_CORE_PATH.'model/modx/modx.class.php';  

// Create an instance of the MODx core
$modx = new modX();

// Initialise the core to access the default 'web' context

// Set a value in the desired session variable