【问题标题】:Cookies doesnt showup in Firefox with $_COOKIE but visible in firebug and works on other BrowsersCookie 不会在带有 $_COOKIE 的 Firefox 中显示,但在 firebug 中可见并且适用于其他浏览器
【发布时间】:2014-10-25 06:15:49
【问题描述】:

我使用wordpress,我设置cookie的目的是为了在Chrome和其他浏览器上完美运行,但在Firefox中不行,当我在firefox中打印$_COOKIE时它是空的,但实际上包含 cookie,相同的代码在其他浏览器上打印 cookie,当然 cookie 在 Firefox firebug 中可见,但在 $_COOKIE 上不可见。

谁能告诉我如何访问它们?什么是限制?如何解决? 我的代码是这样的

if(isset($_GET['attr'])){
    $inTwoMonths = 60 * 60 * 24 * 60 + time();
    $attr = $_GET['attr'];
    setcookie('attr', $attr , $inTwoMonths,'/');
    print_r($_COOKIE);
}

【问题讨论】:

  • Common Pitfalls: Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires.

标签: php wordpress cookies mozilla


【解决方案1】:

setcookie() 只为响应准备一个 Cookie 标头,但它不会实际设置 $_COOKIE 中的值。 $_COOKIE 将在下一次请求后从客户端接收到更新的 cookie 数据时具有新值。见http://php.net/setcookie。在您的代码中,您必须这样做:

setcookie('attr', $attr , $inTwoMonths,'/');
$_COOKIE['attr'] = $attr;

为了使 cookie 中的值在同一个请求中可用。

【讨论】:

  • 啊,不知道,我以前是单独用setcookie函数设置的,但是无论如何设置cookie,我可以在调试器的net选项卡上看到它们,唯一的问题是它们无法访问,一般为我们登录了,我们确实还有一些其他 cookie,所以它们会打印在 Chrome 上,但不会打印在其他浏览器上。
  • 你是什么意思他们不可访问?你的意思是设置在 $_COOKIE 中?
猜你喜欢
  • 2011-12-10
  • 2012-07-28
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
  • 2020-02-10
  • 2016-11-30
相关资源
最近更新 更多