不缓存页面对于数据实时性要求很强的功能来说很重要,以下是 HTML、ASP、PHP 强制不缓存页面的代码。
HTML 强制页面不缓存代码
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
<!-- end no cache headers -->
ASP 强制页面不缓存代码
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl = "no-cache"
Response.AddHeader "Expires",Date()
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "Cache-Control","private, no-cache, must-revalidate"
PHP 强制页面不缓存代码
以下代码即可强制浏览器不缓存页面内容,适用于 HTTP/1.0 及 HTTP/1.1
header(‘Expires: Sat, 26 Jul 1997 05:00:00 GMT‘);
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‘);
时间: 2024-11-11 10:50:55