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???
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???
Share Improve this question asked Jun 5, 2019 at 22:57 billyagbillyag 112 bronze badges1 Answer
Reset to default 1Solved : 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