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. Commented Aug 28, 2020 at 6:48
  • Are you sure the component isn't redefining the namevar session variable? Commented Aug 28, 2020 at 7:28
  • Hi @Lodder yes, I'm sure that I am not redefinint the namevar Commented Aug 28, 2020 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? Commented Aug 29, 2020 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! Commented Sep 4, 2020 at 16:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.