When I include the Joomla framework, the Joomla session seems to be overwriting the session that I am using in another script.
How can I get information from the first session AND from Joomla?
DETAILS
I started a session in a php script external to Joomla.
That file is file1.php
<?php
session_start();
$qid[0]=1;
$qid[0]=2;
$qid[0]=3;
$_SESSION['qid']=$qid;
?>
I then have a php script called main.php It includes 2 files, getsessdata.php and getjoomla.php
main.php
<?php
include("getsessdata.php");
include("getjoomla.php");
?>
I can get the session data from main.php if getjoomla.php is not included.
var_dump($_SESSION); Shows that the session data for qid is missing when getjoomla.php is included.
getsessdata.php
<?php
session_start();
$qid=$_SESSION['qid'];
?>
getjoomla.php
<?php
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' );
require_once (JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'environment'.DS.'request.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
?>
QUESTION:
How can I access the session information from file1.php and still access data from getjoomla.php ? Why am I losing the information from the first session?
Not sure if this helps, but once I have the session data from file1 in main.php the session is no longer needed.
Going on the use of $mainframe, I’m guessing Joomla! 1.5.x.
When you call JFactory::getApplication(‘site’) in it’s construction, a new session is created using session_start() with a passed in Id, this blows away any previous session.
More specifically when JSession is called it’s __construct calls _start
To get around this you could try* this:
put your data in a namespace in $_SESSION
pass an option array after the ‘site’ value, eg. your session namespace.
->
HTH.
*I’m not 100% sure of the mechanics but it should be close.