Php 我能';t自动刷新浏览器并清除缓存
我从头创建了一个PHP网站,每次我上传主机帐户上的更改时,我都必须清除浏览器设置中的chache/cockies。我怎样才能用代码来做呢?我不想让用户自己这样做,以防我再做一次更改。谢谢大家! 您需要发送正确的头以防止缓存。对于纯PHP生成的内容,在发送任何其他输出之前,每个页面发送一次这样的内容将起作用-Php 我能';t自动刷新浏览器并清除缓存,php,html,Php,Html,我从头创建了一个PHP网站,每次我上传主机帐户上的更改时,我都必须清除浏览器设置中的chache/cockies。我怎样才能用代码来做呢?我不想让用户自己这样做,以防我再做一次更改。谢谢大家! 您需要发送正确的头以防止缓存。对于纯PHP生成的内容,在发送任何其他输出之前,每个页面发送一次这样的内容将起作用- <?php header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("C
<?php
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");
?>
对于无法执行此操作的非编程生成的文件(图像、.js文件、.css等),可以配置web服务器以通知客户端限制缓存生存期。当然,这是由客户按照指示
从
#打开模块。
过期于
#设置默认到期时间。
ExpiresDefault“访问加2天”
ExpiresByType图像/jpg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType图像/png“访问加1个月”
ExpiresByType文本/css“访问加1个月”
ExpiresByType文本/javascript“访问加1个月”
ExpiresByType应用程序/javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
ExpiresByType文本/css“现在加1个月”
ExpiresByType图像/ico“访问加1个月”
ExpiresByType图像/x图标“访问加1个月”
ExpiresByType text/html“访问加600秒”
对于
nginx
和其他http服务器,也可以进行类似的配置-请参见您应该阅读以下问题:这不是真正的PHP问题,而是web服务器问题。
<IfModule mod_expires.c>
# Turn on the module.
ExpiresActive on
# Set the default expiry times.
ExpiresDefault "access plus 2 days"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType text/css "now plus 1 month"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 600 seconds"
</IfModule>