If you want to create session in any external file in joomla then please follow these steps for do it, By default you can't create session directly in joomlaJust Copy code given below and paste it in TOP of your external file where you want mainten session OR create new session
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('name','value'); //Set session name and value echo $session->get('name'); //Get session valueThats all Enjoy Code!
3 Replies to “How to set session in external file in Joomla 2.5 ?”
hy, the problem is that, joomla create a new session on the external location, and sometimes i get:
A session had already been started – ignoring session_start() and
Cannot modify header information – headers already sent by
there is any work a round for that? i am using joomla for the main site and cakephp for the secound.
thank so much for this code, it is very helpful;