【问题标题】:PHP Cookie lost after browser closes - Browser = Default Settings浏览器关闭后 PHP Cookie 丢失 - 浏览器 = 默认设置
【发布时间】:2011-11-18 23:53:43
【问题描述】:

我将php过期时间设置为1周;如果离开页面并返回 cookie 仍然存储。当我完全关闭浏览器时,它会丢失存储的 cookie。浏览器未设置为退出后清除 cookie。 (在 chrome、firefox、safari 中失败)

setcookie("pass", "key", time()+259200, "/", ".domain.com" );

【问题讨论】:

  • 什么返回 time() + 259200,也许服务器设置了错误的日期?还要检查响应头,看看 Set-Cookie 头是什么样的
  • 259200 是我手动设置的数字。服务器的日期也是正确的。标头显示 cookie 存储正确,当我退出任何浏览器时它会丢失,这很奇怪。
  • 请发布您收到的确切 Set-Cookie 标头,以便我们仔细查看 :)
  • 设置Cookie:用户=测试; expires=2011 年 9 月 17 日星期六 14:10:55 GMT;路径=/;域=./cutout/.com

标签: php cookies


【解决方案1】:

我不知道这是否有帮助。但我这样做是为了设置一个 cookie。工作多年

$cookie_expire = time() + (86400 * 7);
$domain = $_SERVER["HTTP_HOST"];

if (empty($_COOKIE['entry'])){
    $entry_cookie = $_SERVER['HTTP_REFERER'];
    setcookie('entry', $entry_cookie , $cookie_expire , '/', $domain, false, true);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 1970-01-01
    • 2014-08-10
    • 2011-02-01
    • 2011-04-11
    相关资源
    最近更新 更多