简体   繁体   English

如何使用 php 强制浏览器刷新缓存?

[英]How can I force browser to refresh the cache with php?

I am a beginner web "developer".我是初学者 web “开发者”。 I'm making the site of our dog kennel.我正在建造我们的狗窝。 I've been facing the cache problem for days.几天来我一直面临缓存问题。 I found out PHP filemtime could do the job, I just want to ask, if I put the PHP code like this, would it work?我发现 PHP filemtime 可以完成这项工作,我只想问,如果我这样输入 PHP 代码,它会工作吗? If not, could you help me please, how to do this?如果没有,你能帮我吗,如何做到这一点?

<link rel="stylesheet" type="text/css" href="../../../styles/basic.css?v=<?php filemtime('../../../styles/basic.css') ?>"/>

A typical web server, such as Apache, uses the time of file modification to inform a web browser of a requested page's age, allowing the browser to take appropriate caching action.典型的 web 服务器,例如 Apache,使用文件修改时间通知 web 浏览器请求页面的年龄,允许浏览器采取适当的缓存操作。 With dynamic web pages, the actual PHP script使用动态 web 页面,实际的PHP 脚本


Solutions解决方案

There are two possible approaches we could take to solving this problem: using HTML meta tags , and using HTTP headers .我们可以采取两种可能的方法来解决这个问题:使用HTML 元标记和使用HTTP 标头

HTML meta tags HTML 元标签

 <meta http-equiv="expires" content="Mon, 26 Jul 1997 05:00:00 GMT"/> <meta http-equiv="pragma" content="no-cache" />

HTTP headers HTTP 接头

<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Pragma: no-cache');
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM