I'm setting multiple session variables in a PHP script that is external to Joomla.
The variables are set consecutively using the following code.
//Access Joomla
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$app = JFactory::getApplication('site');
$app->initialise();
//Store values in Joomla Session
$session = JFactory::getSession();
$session->set('firstvalue', $firstvalue);
$session->set('secondvalue', $secondvalue);
$session->set('thirdvalue', $thirdvalue);
$session->set('fourthvalue', $fourthvalue);
In another script I then get the session variables
$session = JFactory::getSession();
$firstvalue = $session->get('firstvalue');
//etc etc
The problem I'm seeing is that the value for firstvalue occasionally goes missing. I'm not sure if this happens to the other variables yet. From what I've read, it's possible that Joomla is not locking the session. What I think that means is that Joomla tries to set firstvalue, but before it gets saved it is overwritten by another variable. Does this sound right?
If my understanding of the situation is right, I've come up with a few solutions. If you have some better ones I'd love to hear them :)
I could
- store the variables in an array and set them in one go.
- create different namespaces for each of the variables.
In summary,
I'd like to know if setting Joomla session variables consecutively in a script external to Joomla could cause some values to be lost. If that is unlikely, I'd appreciate suggestions as to what could be causing the data loss and suggestions on how to solve the problem.