About using session variables

More
10 years 3 months ago #44438 by Hableur
Hello,
bonjour et bonne année à tous.

I have a problem after updating Flexi.

In my flexitemplate, I put a value in a session variable in category view to use it in item view. It was working nice.

Now, after updating, the session variable is modified when I click on a item for viewing it, like if the template category was called again before going to the item template.

Yet, it is the template item who comes on the screen !How is it possible my session variable is revised by category template when I want to see an item ??

Thanks a lot.

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

More
10 years 3 months ago #44439 by ggppdk
Hello

FLEXIcontent does not overwrite session otherwise Joomla would not work,

what is the session (variable) name used to store your data ?


-- also problem maybe with session variable contents, these are saved into the DB,
some characters may break DB query ?!

Try this:

$conf = base64_encode(serialize($data));
// then set into session

// get from session
$conf = unserialize(base64_decode($conf));


-- 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.

More
10 years 3 months ago #44462 by Hableur
Hello ggppdk, thanks for your answer.

I just put some html code in a session variable. I try whith many name as $_SESSION, $_SESSION and so on.

What I don't understand :

The session variable is filled in category_items.php when I call the category template. In this category views, items are displayed in a list on screen. When I click on a item link for displaying it, the value of my variable session is renewed, like if category_items.php was called again before displaying item view.

An example :
If in category_items.php, I put $_SESSION=time(); and echo $_SESSION; It displays (for exemple !) 456230123.

In item.php, I put echo $_SESSION; When I choose an item for displaying in category view, then $_SESSION is displayed on the item screen. But the value has changed, for exemple 456230154. So, my session variable has been recalculated passing through category_items.php when I call item displaying. My session variable is modified only in category_items.php.

Thanks for your attention.

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

More
10 years 3 months ago #44465 by ggppdk
Hello

-- FLEXIcontent will not overwrite session nor use $_SESSION variable directly

but Joomla will probably overwrite this variable


-- A -- you can try doing
session_start();
before using $_SESSION



-- B -- In Joomla the proper way is:
Code:
// 1. Get a reference to session object $session JFactory::getSession(); // 2. GET/SET a session variable // Set a session variable $session->set('myvariable', 'yes'); // Get a session variable echo $session->get('myvariable');
Regards


-- 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.

More
10 years 3 months ago #44466 by Hableur
Thanks.

I try with the A and B solutions, it exactly the same than i have observed.

The variable session is modified when you click on a item to make it displaying.

So,
or : when a item is to be displayed, category-items.php is reused (it seems no possible, in fact),

or : when you click on item link in category view, category_items.php is played again before leaving to go to item view.

Nothing possible else. It's higtly improbable than Joomla use 'toto' (who is a nickname for jokes) like session variable name, and it's impossible Joomla rewrite it with the same rules that I have defined in category_items.php.

Regards

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

More
10 years 3 months ago #44467 by ggppdk
Hello

-- there are data that cannot be stored in the joomla session

i guess something is storing data into the session that makes Joomla DB query to fail
(i mean the DB query used to store session data)




-- To make sure that your data are not the cause of the problem do for this:

For storing:
Code:
//Get session object $session = JFactory::getSession(); // Make data safe for DB storage $mydata_safe = base64_encode(serialize($mydata)); // Store data into session $session->set('myvariable', $mydata_safe, 'myarea');


For retrieving:
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));


-- 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.311 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