简体   繁体   中英

Joomla session variable not found in a php

I am setting a session variable in an Article:

 $session->set('test' , 'testing' ); 

As long as I stay within other Joomla modules and articles I can read it without problem.

$db = $session->get('test' , '' );

But when I execute a php that is called by a XMLHttpRequest within a Javascript (everything in the same folder), it doesnt find the session variable and returns the default value.

What am I missing?

If you want to declare those session values are variables you can read from anywhere in Joomla you should be using the setUserState and getUserState methods.

For example if you want to set a session variable named test your could do this:

$app = JFactory::getApplication();
$app->setUserState('test','my test value');

Then if you want to call that anywhere else in Joomla just set it to a variable using getUserState like this:

$app = JFactory::getApplication();
$mySessionVariable = $app->getUserState('test');
echo $mySessionVariable;

Here is a link to the session state variables documentation for Joomla: Joomla User State Variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM