0

I am programming a little component and module in Joomla.

My component and module reads a variable from the php session (this variable is set before for external php script).

External php script:

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();

//session_start();
$session = JFactory::getSession();      
$session->set('namevar', base64_encode('message'));`

Joomla's module and component (have the same code):

$session = JFactory::getSession();
$mymessage = $session->get("namevar");
echo $mymessage ;

The curious thing is that: -The module works fine. -The component does not work (and if I do a var_dump($mymessage) it shows NULL).

Moreover, this code works the time after :S

Any idea why this doesn't work the first time?

5
  • Welcome to JSE. Please take our tour while you wait for support. – mickmackusa Aug 28 '20 at 6:48
  • Are you sure the component isn't redefining the namevar session variable? – Lodder Aug 28 '20 at 7:28
  • Hi @Lodder yes, I'm sure that I am not redefinint the namevar – mreig Aug 28 '20 at 7:47
  • After you define $session, I would be inclined to dump the $session in your both your module and then your component view, and vice versa; then you should be able to see namevar and its value. If that checks out; how are you including the external script? – Grant G Aug 29 '20 at 23:32
  • Hello @GrantG, I have done: echo hello world + the code of question and after define $session a var_dump. Result: It shows empty, in other words, any error do that the firstly hello world not appears. Without var_dump the hello world shows well. More info: If I see the joomla debug, the var is correct in the php session. Thanks! – mreig Sep 4 '20 at 16:38

Your Answer

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

Browse other questions tagged or ask your own question.