dqkf36241 2015-04-29 22:25
浏览 53

第二次访问时刷新网站[重复]

This question already has an answer here:

I would like to "force-load" an instance of a page every time it's accessed.

The website in question is a "build your custom product"-kind of site and uses a multi-step form to guide customers through the steps of the product building. The client wants the site to be such that every time a user access the site, whether by direct url or by clicking on the "back" and "forward" buttons on the browser, it must refresh. In other words, no caching (right?).

I've tried to use the solutions I found on SO and on other websites, which mainly consisted of

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

But that didn't work.

So I tried my own solution:

$location = "/fabriquer/";
if(isset($_COOKIE['first_load']) && $_COOKIE['first_load'] == "true") {
    setcookie('first_load', 'false');
    header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . $location);
} else {
    setcookie('first_load', 'true');
}

But that also seems to not be working properly. When I press the back button on my browser to get back on that site, the refresh does not happen, but the cookie is set to true/false in the second solution.

Any ideas?

</div>
  • 写回答

2条回答 默认 最新

  • dro60731 2015-04-30 02:25
    关注

    The only way you can get the browser to nto cache the page is to change the url every time. For instance append a random number or datetime as a param

    $url = $url.'?ver='.rand(1,1000);
    

    Add this to every url as you go from one page to another. I add a version number on mine. That way, whenever I update the site, everyone gets fresh copies.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了