How set session in external file in joomla 2.5 ?


Hello,

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__).'/' ));
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 value

Thats all

Enjoy Code!

Advertisements

Sr. Software Engineer

Tagged with: , ,
Posted in Joomla
3 comments on “How set session in external file in joomla 2.5 ?
  1. Constantin Zaharia says:

    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.

  2. MANGA says:

    thank so much for this code, it is very helpful;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: