For a small intranet site, I have a dynamic (includes AJAX) page that is being cached incorrectly by Firefox. Is there a way to disable browser caching for a single page?
对于一个小型的内部网站点,我有一个动态(包括AJAX)页面被Firefox错误地缓存。是否有一种方法可以禁用单个页面的浏览器缓存?
Here's the setup I'm using:
下面是我使用的设置:
- Apache under XAMPP, running on a Windows server
- 在XAMPP下运行的Apache
- PHP
- PHP
Clarification
The content that I'm primarily concerned about is page text and the default options in some <select>
s. So I can't just add random numbers to the end of some image URLs, for example.
我主要关心的内容是页面文本和一些
Update:
I followed the suggestions I've gotten so far:
我遵循了我到目前为止得到的建议:
- I'm sending nocache headers (see below)
- 我将发送nocache标题(见下面)
-
I'm including a timestamp URL parameter and redirecting to a new one if the page is reloaded after 2 seconds, like this:
我将包含一个时间戳URL参数,如果页面在2秒后重新加载,则将重定向到一个新参数,如下所示:
$timestamp = $_GET['timestamp']; if ((time()-$timestamp) > 2) { header('Location:/intranet/admin/manage_skus.php?timestamp='.time()); }
Now Firebug shows that the headers specify no cache, but the problem persists. Here are the response headers for the page:
现在,Firebug显示header没有指定缓存,但是问题仍然存在。以下是该页面的响应头:
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
6 个解决方案
#1
9
Add current timestamp as parameter of url, e.g.
添加当前时间戳作为url的参数,例如。
http://server.com/index.php?timestamp=125656789
#2
4
I think this tells you what you want:
我想这告诉你你想要什么:
http://www.thesitewizard.com/archive/phptutorial2.shtml
http://www.thesitewizard.com/archive/phptutorial2.shtml
Look for "Preventing the Browser From Caching"
寻找“阻止浏览器缓存”
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" );
#3
3
You should send the following header:
你应该发送以下标题:
Cache-control: no-cache
in the HTTP response.
在HTTP响应。
#4
1
You could add these headers:
您可以添加以下标题:
Cache-Control: no-cache
And (for backward compatibility with HTTP/1.0 clients)
和(用于与HTTP/1.0客户端向后兼容)
Pragma: no-cache
#5
1
Here's another take that isn't PHP specific.
这里还有另外一个不是PHP特有的。
Try this in your <head> </head>
section:
在你的 section:
<meta http-equiv="cache-control" content="no-cache, no store"/>
<meta http-equiv="Expires" Content="Mon, 25 May 2009 19:07:03 GMT">
Found that at the end of a long thread here:
发现在这一长串的结尾:
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
#6
0
Use the header() function. You have to set a few to cover all browsers; see http://www.php.net/manual/en/function.header.php#75507
使用header()函数。你必须设置一些来覆盖所有浏览器;见http://www.php.net/manual/en/function.header.php # 75507
#1
9
Add current timestamp as parameter of url, e.g.
添加当前时间戳作为url的参数,例如。
http://server.com/index.php?timestamp=125656789
#2
4
I think this tells you what you want:
我想这告诉你你想要什么:
http://www.thesitewizard.com/archive/phptutorial2.shtml
http://www.thesitewizard.com/archive/phptutorial2.shtml
Look for "Preventing the Browser From Caching"
寻找“阻止浏览器缓存”
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" );
#3
3
You should send the following header:
你应该发送以下标题:
Cache-control: no-cache
in the HTTP response.
在HTTP响应。
#4
1
You could add these headers:
您可以添加以下标题:
Cache-Control: no-cache
And (for backward compatibility with HTTP/1.0 clients)
和(用于与HTTP/1.0客户端向后兼容)
Pragma: no-cache
#5
1
Here's another take that isn't PHP specific.
这里还有另外一个不是PHP特有的。
Try this in your <head> </head>
section:
在你的 section:
<meta http-equiv="cache-control" content="no-cache, no store"/>
<meta http-equiv="Expires" Content="Mon, 25 May 2009 19:07:03 GMT">
Found that at the end of a long thread here:
发现在这一长串的结尾:
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
http://forums.mozillazine.org/viewtopic.php?f=25&t=673135&start=75
#6
0
Use the header() function. You have to set a few to cover all browsers; see http://www.php.net/manual/en/function.header.php#75507
使用header()函数。你必须设置一些来覆盖所有浏览器;见http://www.php.net/manual/en/function.header.php # 75507