Setting and checking Cookie with PHP not working i

2019-08-25 18:45发布

I am having a really weird issue.. I am trying to set a cookie, and it works perfectly fine in all browsers except for Safari, both desktop and iOS Safari.

The weird thing is that I can see that it is being set because in Safari's inspector it shows the cookie as it should.

When I try to access the cookie using $_COOKIE["wpcode"] it does not show it, but in other browsers it does...

Going a step further, doing print_r($_COOKIE) does not display ANY cookies, though in my cookie panel there are a bunch of cookies set.

I am using Safari 8, but the issue occurs on all versions of Safari that I have tested (6.2+)

I am using WPEngine as a host, and I am using WordPress as well.

The code I am using to set my cookie is (but I have tried it every possible way I have found):

setcookie("wpcode", md5("true"), time()+60*60*24*7,"/", "", false);

I am trying to access the cookie like:

$_COOKIE["wpcode"] != md5("true")

Though I have tried everything like:

isset($_COOKIE["wpcode"])

This must obviously be an issue with Safari, I have looked through every page in Google regarding similar issues with no results...

Thanks!

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-25 19:11

Sorry for being late to the party but I just ran into this issue myself. Turns out that WP Engine's aggressive caching makes retrieving cookies via php difficult / impossible.

WP Engine - Cookies and PHP Sessions

Looks like I'll need to use .js I hope despite my tardiness this answer gives you some closure.

查看更多
登录 后发表回答