【问题标题】:Why are cookies set with `setcookie` starting with a dot?为什么 cookie 设置为以点开头的 `setcookie`?
【发布时间】:2019-10-14 21:55:21
【问题描述】:

例子:

<?php
setcookie('test_cookie', '1', time()+3600, '/', $_SERVER['SERVER_NAME']);
echo $_SERVER['SERVER_NAME'];  // outputs: entwicklung.hausfux

Afaik 点是通配符选择器。

这会导致login problems if you are trying to login into subdomain websites.

【问题讨论】:

标签: php cookies


【解决方案1】:

有两个例子。

n1.example.com and .n1.example.com

n1.example.com 用于域,.n1.example.com 用于子域。 子域设置点值。它仅用于子域作为从其父域继承 cookie。

【讨论】:

    【解决方案2】:

    我发现如果你在 setcookie 函数中省略了 cookie 域参数,那么它会设置当前域名,开头没有点。

    setcookie('test_cookie', '1', time()+3600, '/');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 2018-06-05
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多