最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

https - wordpress can't read a cookie?

programmeradmin3浏览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???

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论