About using session variables

More
10 years 3 months ago #44470 by Hableur
Well, it doesn't work best, and it's logical.

The problem isn't that the data in variable session are wrong or corrupted, the problem is the data are rewrote when you leave category template for item template.

So, I putted in category_items.php:
Code:
$session = JFactory::getSession(); $mydata =time(); echo $mydata; // Make data safe for DB storage $mydata_safe = base64_encode(serialize($mydata)); // Store data into session $session->set('myvariable', $mydata_safe, 'myarea');
and it print 1390752334 to the screen of category view.

I putted in item.php :
Code:
// Get session object $session = JFactory::getSession(); // Get data from session $mydata_safe = $session->get('myvariable', 'default_value', 'myarea'); // Decode / unserialize data $mydata = unserialize(base64_decode($mydata_safe)); echo $mydata;
and it print 1390752356 in the item view.

The content of 'myvariable' has been rewritten when I have clicked on item link.

And I not only have used time(), but also a random value in a array.

The conclusion is that category_items.php is reused when you click on a item link.

Please Log in or Create an account to join the conversation.

More
10 years 3 months ago #44471 by ggppdk

Hableur wrote: the problem isn't that the data in variable session are wrong or corrupted, the problem is the data are rewrote when you leave category template for item template.


reused ?
yes, page maybe reloaded for some reason

e.g.
your browser may preload/reload some page due to some plugin

your code should be checking setting session variable only once


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.242 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline