【问题标题】:Setting Cookie with jQuery on root path (/) not accessible to subdirectories on internet explorer 9Internet Explorer 9 上的子目录无法在根路径 (/) 上使用 jQuery 设置 Cookie
【发布时间】:2013-01-06 01:26:21
【问题描述】:

我正在使用以下代码在根目录上设置一个带有 jQ​​uery 的 cookie:

$.cookie('key', 'value', {
    path: '/',
    expires: 30
});

然后我在整个网站上读取 cookie,但 IE9 只会在主页 (www.example.com/) 上找到 cookie,而不是其他页面 (www.example.com/subdir 或 www.example.com/subdir/sub)。

事实上,当我在任何子目录页面上var_dump($_COOKIE) 时,我得到的只是array(0) {}

我可以通过缓存 -> 查看 cookie 信息来查看 cookie。它在那里并设置为/。

在所有其他浏览器中都能完美运行。

【问题讨论】:

    标签: php jquery internet-explorer cookies path


    【解决方案1】:

    经过一番研究,我们得出的结论是,问题实际上是 W3 Total Cache 的缓存问题。

    【讨论】:

      【解决方案2】:

      设置你的cookie如下:

      $.cookie('key', 'value', { path: '/', domain: 'example.com', expires: 30 });
      

      更多信息请查看Cookies and domains

      希望对你有帮助。

      【讨论】:

      • 感谢您的回复。这几乎奏效了。我用域设置了 cookie,但现在如果我在子目录页面上设置 cookie,则在主(根)页面上找不到 cookie。我的 var_dump($_COOKIE) 显示了一系列其他 cookie,但找不到我的 cookie。再次,我可以从缓存中查看 cookie -> 查看 cookie 信息,现在仅在几个看似随机的子目录页面上使用 var_dump($_COOKIE) 找到了 cookie。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 2010-10-22
      • 2014-05-06
      • 2021-05-26
      • 2015-11-13
      • 1970-01-01
      相关资源
      最近更新 更多