Single page and session persistence problems - cannot pass / maintain session variables3 users found helpful
I have searched the forums and found people with similar problems, but no solution.
I am able to set session variables, which persist across different pages, from most locations, except from a single page, and blocks that exist on a single page.
I have created a package, which creates a single page, front-end. On this, I have placed a block that collects some user details via a form so they can receive a brochure. I want to persist the user's data across page views, via a session, so they don't have to repeatedly fill in this form.
In both the single page's controller, and in the block's controller, I have set up test sessions, none of which persist when navigating away from the single page. This is only an issue on the single page. The same session test code, when placed on non-single pages and blocks that don't appear on the single page, persists fine.
I have tried defining the session name, and manually starting the session on the single page controller, and the block controller, but this has no effect
All help much appreciated.
// set $_SESSION['my_namespace']['my_keyname'] = $my_value; // get $my_value = $_SESSION['my_namespace']['my_keyname'];
Thanks for that, however, that was the method I was using to set and get the session
// set the session $_SESSION['brochure']['test_single'] = 'Session from Single page'; // get the session print_r($_SESSION);
This works fine in block controllers where the blocks aren't on the single page, and persists across different pages. I can set a session fine on a the single page, from its controller, or a block's controller, but it disappears when navigating away from the single page. Same problem with cookie setting and getting.
Does it recover when you come back to the single page? or is it gone completely?
At a guess, the root of the problem will be something to do with cookies simply because session info is associated by cookies.
I have a free block 'Quick Param View' that may help with diagnostics (or it may tell you nothing you don't already know).
Thanks for your help. I am outputting all those server globals during my debugging already.
The sessions do not appear again when you return to the single page, upon leaving the single page they are gone for good.
Very frustrating! I will try to investigate the core, and see they may be getting unset somewhere. Will update if I find a fix.
I don't know if this is going to help but I tried this in C5 22.214.171.124 and it worked:
In the controller for the register page (which is a non-dashboard single page as you know), after making sure there were no missing fields, I added the 2 lines
session_start(); $_SESSION['my_totally_random_name'] = $username;
Then, I added a PHP block to the home page and to another random page (so both not single pages). In that block I added the 2 lines:
After registering a bogus account, I went to the home page where my little text along with the new user name was printer. Then from there I went to my other page and same result. So it seems that session variables are passed from the single page to the others.
Hope this helps.
Shouldn't you NOT have to call session_start(), since it is already be called within the session.php file from Concrete5 Core?
I tried a second test without logging in at all. My session variable is set when the register page is loaded. Going away from that page to the home page or the other one still allows me to retrieve the session variable succesfully.
I am having exactly the same problems as dojoDesign described..
I described my Problem here:
Is there any Solution to that problem?
Technically you don't need session_start but if session already is started it won't hurt.
For your other question, I answered in your other thread.
Finally I assume I figuered out, what the cause for my problems was:
Problem was, that the full page cache was turned on globally for all pages. So when the user came on the page, logged in, he never got actual data based on his user id written in a session variable, the page was just loaded from cache containing I assume the data from the last cache rebuild, which is either no data or data from another user, if one was logged in and on that page while the cache was rebuild.
So within the view method of the controller, the data was being loaded correctly based on the user Id from the session and then passed to the view, but somehow within the view, the variable was overritten by content coming from the full page cache.
So it kinda seems, that the full page cache seems to oversteer session variables.
Does that even sound plausible to you guys? Is that maybe a bug or even desired behaviour? It seems pretty weird to me..