Tuesday, July 17, 2012
Joomla 2.5: set session inside & get session outside
We have a need to set a session in joomla extension (e.g. component) and get (read) session in a external file (outside joomla).
Here is the sample code:
//set session in a joomla extension
$session =& JFactory::getSession();
$session->set('asession', 'avalue');
//get session in a external file (outside joomla)
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' )); //should change to match to your file directory
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$session =& JFactory::getSession();
$asessionvalue = $session->get(' asession ');
Subscribe to:
Post Comments (Atom)
This does not work in Joomla 2.5 with $mainframe gone.
ReplyDeleteI have tested on Joomla 2.5, this code works.
ReplyDelete