【问题标题】:No-cache and cookies issue无缓存和 cookie 问题
【发布时间】:2017-03-05 15:21:42
【问题描述】:

我正在创建一个小商店并使用 cookie 来存储购买的物品。 将商品添加到购物车时,我会执行以下操作:

document.cookie="itemname=added";

然后我有一个按钮可以进入购物车,然后在 php 中执行:

foreach($_COOKIE as $cookie=>$value)
{
    if ($value=="added")
          ...something
}

除了我需要重新加载页面以使商品显示在购物车中之外,一切正常。如果我将?u=randomvalue 添加到购物车链接,它也可以工作,但由于某些原因它非常烦人。

这是我的 html 标头:

<!DOCTYPE HTML>
<html lang="fr">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link href="/style.css" rel="stylesheet" type="text/css">

<title>Shop</title>
<meta name="description" content="">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

</head>

有什么我忘记了吗?

谢谢

【问题讨论】:

    标签: javascript php cookies


    【解决方案1】:

    我不得不添加这样的 php 标头:

    <?
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache");
    header("Cache-Control: post-check=0, pre-check=0");
    header("Pragma: no-cache");
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-07
      • 2012-10-15
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多