防止本地主机上的后退按钮缓存

问题描述 投票:0回答:1

我有 Apache 在 Windows 机器上运行 PHP。

在我的本地网站上,如果我以用户身份注销,则 cookie 将被清空,并且在标头重定向后我将不再登录该网站。纸上谈兵。

但我仍然可以使用浏览器后退按钮并查看仅适用于登录用户的内容。

但是刷新页面确实显示我已经退出,内容没有显示。但后台缓存不同意。

在我使用 https 的实时网站上,这样的反向缓存没有问题。 但在本地服务器上,就会发生这种情况。

我该如何解决这个问题?

这是我在用户注销时使用的:

<?php
// LOG OUT
setcookie('cookie', '', time()+31449600, '/', NULL, FALSE, TRUE);
exit(header('Location: http://localhost/'));
?>

我在网站上所有 php 页面上包含的 php 配置文件中使用这些标头:

<?php
header('Content-type: text/html; charset=utf-8');
header('Expires: ' . gmdate('D, d M Y 00:01:00', strtotime('first day of this month')) . ' GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()-1) . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
?>

编辑:我现在看到问题与“bfcache”(浏览器中的后退缓存)有关。还在调查中..

搜索此类问题时,Google 已经不再是以前的样子了..

php apache security browser-cache
1个回答
0
投票

启用 https (ssl) 解决了缓存页面和后退按钮的问题

© www.soinside.com 2019 - 2024. All rights reserved.