0

This is a recap for my problem - after a form is submitted it will save a token (a cookie token)

function set_cookie_token( $entry, $form ) {
   setcookie('token', 'true', time() + (86400 * 30), "/"); 
}
add_action( 'form_after_submission', 'set_cookie_token', 10, 2 );

function open_dcookie() { 
    if (isset($_COOKIE['token']))
    return $_COOKIE["token"]; 
} 
add_action( 'wp', 'open_dcookie' );

the form works fine since after submission I can see the registration of token in my console.

the problem is my wordpress website will read the cookie if im logged in, but it will not if im not.

this is how i read the cookie

        echo open_dcookie();
        echo  $_COOKIE['token'];

as mentioned, it will only output the cookie if im logged in, it was working on my localhost but when the site was moved to https, i have encountered this problem, so was it the https? is it something about a caching problem? or is my declaration of cookies for an https wrong???

1 Answer 1

1

Solved : WP Engine :rolleyes - When using WPEngine you have to ask them to manually exempt whatever cookies you set otherwise the caching they use will essentially render an empty string and make it look like the cookie wasn't set

1
  • 1
    This is due to caching. With most hosts that have advanced caching configurations, they will ignore most cookies unless they're whitelisted. This has a massive impact on performance of the site overall. Jun 6, 2019 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.