Hoe sessie-variabelen bereiken die door een extern script ingesteld zijn

From Joomla! Documentation

Revision as of 09:42, 8 August 2016 by MartijnM (talk | contribs) (Created page with "Hoe sessie-variabelen bereiken die door een extern script gevuld zijn")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Other languages:
English • ‎Nederlands • ‎español • ‎français

Situation: when you call a session variable in Joomla from an external script, it appears to be empty.


Solution: Replace session_start(); in your external script with

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

require_once ( JPATH_BASE. '/includes/defines.php' );
require_once ( JPATH_BASE. '/includes/framework.php' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

Be sure to change JPATH_BASE to suit your directory structure.

Replace the $_SESSION[ 'name' ] = "value"; in your external script with

$session = JFactory::getSession();
$session->set('name', "value");

Now you can retrieve this session variable using:

$session = JFactory::getSession();
echo $session->get('name');