简体   繁体   中英

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

I am a beginner web "developer". 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? 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. With dynamic web pages, the actual PHP script


Solutions

There are two possible approaches we could take to solving this problem: using HTML meta tags , and using HTTP headers .

HTML meta tags

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

HTTP headers

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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