Single page and session persistence problems - cannot pass / maintain session variables

Permalink 3 users found helpful
Hello,

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

public function on_start() {
                session_name('CONCRETE5');
      if (!session_id())
      session_start();
                ....


All help much appreciated.
Cheers!

senshidigital
 
senshidigital replied on at Permalink Reply
senshidigital
This problem of data persistence from single pages also encompasses cookies as well as session variables.
JohntheFish replied on at Permalink Reply
JohntheFish
I have not tried this on a front end single page, but for dashboard single pages I have used the php global $_SESSION array:
// set
$_SESSION['my_namespace']['my_keyname'] = $my_value;
// get
$my_value = $_SESSION['my_namespace']['my_keyname'];
senshidigital replied on at Permalink Reply
senshidigital
Hi John,

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.
JohntheFish replied on at Permalink Reply
JohntheFish
I don't have any better answer, but its a problem that interests me because I can imagine I will come up against it some time.

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).
http://www.concrete5.org/marketplace/addons/quick-param-view/...
senshidigital replied on at Permalink Reply
senshidigital
Hi John,

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.
mnakalay replied on at Permalink Reply
mnakalay
Hello,
I don't know if this is going to help but I tried this in C5 5.6.1.1 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:
session_start();
echo "thanks for registering, ".$_SESSION['my_totally_random_name'];


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.
janwidmer replied on at Permalink Reply
janwidmer
Hi Mnakalay,

Shouldn't you NOT have to call session_start(), since it is already be called within the session.php file from Concrete5 Core?
mnakalay replied on at Permalink Reply
mnakalay
In the first test, the session variable is set before the new user is logged in and retrieved after it is automatically logged in by the system.

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.
janwidmer replied on at Permalink Reply
janwidmer
Hi All,

I am having exactly the same problems as dojoDesign described..
I described my Problem here:
http://www.concrete5.org/community/forums/customizing_c5/serious-se...

Is there any Solution to that problem?

Thanks Jan
mnakalay replied on at Permalink Reply
mnakalay
Hi,
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.
janwidmer replied on at Permalink Reply
janwidmer
Hi all,

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

Regards Jan