How set session in external file in joomla 2.5 ?


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 joomla

Just 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__).'/' ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$session =& JFactory::getSession();
$session->set('name','value'); //Set session name and value
echo $session->get('name'); //Get session value

Thats all
Enjoy Code!

3 Replies to “How set session in external file in joomla 2.5 ?”

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *