3

I am trying to set a value in external file but the session values are not set correctly. The session is set some times and other times it is not set. I am setting a session using ajax call following is the code in external file.

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' ));
define( 'DS', DIRECTORY_SEPARATOR );

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();
$session->set('continent',123456); //Set session name and value
echo $session->get('continent'); //Get session value 

In ajax call I can get the session values using "$session->get('continent')" but when I try to get the session value in inside Jommla I get null or nothing.

$session =& JFactory::getSession();
echo $session->get('continent');

I just use the above code to get the value. Can some one tell me what wrong I am doing?

2

Your App initialization is not exactly the same than Joomla! CMS. Any minor difference can cause a condition to create a new session, instead of the reusing the original session.

Instead of trying to load the session from an external file, you can just implement a controller task inside the CMS, to avoid any risk of not loading the same session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.