使用PHP设置和检查Cookie在Safari中不起作用 [英] Setting and checking Cookie with PHP not working in Safari

查看:181
本文介绍了使用PHP设置和检查Cookie在Safari中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个很奇怪的问题。.我正在尝试设置一个cookie,它在除Safari,台式机和iOS Safari之外的所有浏览器中都能正常工作。

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.

奇怪的是,我可以看到它已被设置,因为在Safari的检查器中它会按原样显示cookie。

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.

当我尝试访问cookie时使用 $ _ COOKIE [ wpcode] 不会显示它,但是在其他浏览器中会显示...

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

更进一步,执行 print_r($ _ COOKIE)不会显示任何cookie,尽管在我的cookie面板中设置了一堆cookie。

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.

我正在使用Safari 8,但是在我测试过的所有Safari版本(6.2及更高版本)中都会出现此问题

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

我正在使用WPEngine作为主机,我也使用WordPress。

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

我用来设置Cookie的代码是(但是我已经尝试了所有可能的方法来找到它):

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);

我正在尝试访问Cookie,例如:

I am trying to access the cookie like:

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

尽管我已经尝试过所有类似的操作:

Though I have tried everything like:

isset($_COOKIE["wpcode"])

这显然是Safari的问题,我浏览了Google中的每个页面,发现类似问题,但没有结果。 ..

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

谢谢!

推荐答案

对不起,您来晚了晚会,但我本人只是遇到了这个问题。事实证明,WP Engine的激进缓存使通过php检索cookie变得困难/不可能。

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引擎-Cookies和PHP会话

我希望我需要使用.js尽管我迟到了,但这个答案还是让您有些失望。

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

这篇关于使用PHP设置和检查Cookie在Safari中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆