1

I am trying to pass some variable from a PHP module (Sourcerer) to custom PHP script using Sessions method (as posted here). The method works fine between two PHP scripts but when I tried to implement it between a module and a script, it fails.

Overview of the my method :

Code inside php module :

<?php
session_start();
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
?>

Code inside php script :

<?php
session_start();
echo 'Welcome to page #2<br />';
echo $_SESSION['favcolor'];
?>

Help would be appreciated.

3

You shouldn't use using $_SESSION with Joomla, but instead JFactory::getSession().

Try the following:

Module:

$session = JFactory::getSession();
$session->set('favcolor', 'green');

PHP file:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.