5

对于一个小型 Intranet 站点,我有一个被 Firefox 错误缓存的动态(包括 AJAX)页面。有没有办法禁用单个页面的浏览器缓存?

这是我正在使用的设置:

  • XAMPP下的Apache,运行在Windows服务器上
  • PHP

澄清

我主要关心的内容是页面文本和一些<select>s中的默认选项。因此,例如,我不能只在某些图像 URL 的末尾添加随机数。

更新:

我遵循了迄今为止得到的建议:

  • 我正在发送 nocache 标头(见下文)
  • 如果页面在 2 秒后重新加载,我将包含时间戳 URL 参数并重定向到新参数,如下所示:

    $timestamp = $_GET['timestamp'];
    if ((time()-$timestamp) > 2) {
        header('Location:/intranet/admin/manage_skus.php?timestamp='.time());
    }
    

现在 Firebug 显示标头没有指定缓存,但问题仍然存在。以下是页面的响应标头:

Date    Fri, 25 Sep 2009 20:41:43 GMT
Server  Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8
X-Powered-By    PHP/5.2.8
Expires Mon, 20 Dec 1998 01:00:00 GMT
Last-Modified   Fri, 25 Sep 2009 20:41:43 GMT
Cache-Control   no-cache, must-revalidate
Pragma  no-cache
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Transfer-Encoding   chunked
Content-Type    text/html
4

6 回答 6

9

添加当前时间戳作为 url 的参数,例如

http://server.com/index.php?timestamp=125656789
于 2009-09-25T20:16:52.533 回答
4

我想这告诉你你想要什么:

http://www.thesitewizard.com/archive/phptutorial2.shtml

寻找“防止浏览器缓存”

header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
于 2009-09-25T20:18:52.920 回答
3

您应该发送以下标头:

Cache-control: no-cache

在 HTTP 响应中。

于 2009-09-25T20:18:14.933 回答
1

您可以添加这些标题:

Cache-Control: no-cache

并且(为了向后兼容 HTTP/1.0 客户端)

Pragma: no-cache
于 2009-09-25T20:18:59.027 回答
1

这是另一种不是 PHP 特定的方法。

<head> </head>在你的部分试试这个:

<meta http-equiv="cache-control" content="no-cache, no store"/>
<meta http-equiv="Expires" Content="Mon, 25 May 2009 19:07:03 GMT">

发现在一个长线程的末尾:

http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75

于 2009-09-25T21:08:52.397 回答
0

使用 header() 函数。您必须设置一些以覆盖所有浏览器;见http://www.php.net/manual/en/function.header.php#75507

于 2009-09-25T20:22:26.080 回答