• Resolved ChromaDot

    (@soojooko)


    I have a form on a cached page which sends its $_POST data to another page. This page also defines a $_SESSION variable. The $_POST data makes it fine to the target page, but the $_SESSION variable is not defined. If I turn the cache off, there is no problem. I know I can exclude the first page from the cache entirely, but I would like this page to be included as it contains many cacheable resources.

    My question is, should $_SESSION variables defined on a cached page get lost when visiting another page?

    • This topic was modified 6 years ago by ChromaDot.
    • This topic was modified 6 years ago by ChromaDot.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    Is there any way I can recreate this on my end?

    Thread Starter ChromaDot

    (@soojooko)

    Hi Hristo. Thanks for getting back to me.

    Ok, so set up a wordpress page with dynamic cache turned on. In the page template PHP, define a $_SESSION variable. for example:-

    session_start();
    $_SESSION[‘test’] = “test session”;

    If you visit that page, the session variable should be defined. However, when I then visit another page and try to output the variable using: echo $_SESSION[‘test’], it is undefined.

    With dynamic cache turned off, the above works fine; the variable is echoed correctly.

    I’ve noticed that any changes to my theme PHP files are not reflected on the website with dynamic cache turned on. This wasn’t the case a few weeks ago – where I could edit my PHP and refreshing the browser would reflect the changes. Has the way dynamic cache works been changed recently? – as before both session variables and PHP changes seemed to get picked up with the cache on, but not any more.

    BTW, this is the same across all my websites using SGO. Not an isolated case.

    • This reply was modified 6 years ago by ChromaDot.
    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    It’s a full page caching which means that if you get that request serviced by the cache, we won’t even hit the PHP service but fetch it directly from the reverse proxy. This said, you can use the exclude functionality to remove those pages from the cache completely.

    Thread Starter ChromaDot

    (@soojooko)

    Thanks Hristo. That’s what I thought – but wanted to be sure.

    Ok, to attempt this from a different angle – I know the dynamic cache is disabled for WP logged in users. However, my website has its own independent user login system for access to custom functionality. ( this is what I am using the $_SESSION variables for ). What I would like is to disable the dynamic cache for anybody logged into my custom system ( not the WP login ). Is there any way to programmatically disable the dynamic cache on-the fly? This way, I could keep the dynamic cache for normal visitors, but disable it for users logged in to my system. Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Passing $_SESSION varaible from cached page’ is closed to new replies.