这篇文章主要介绍了php清除浏览器缓存的方法,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

PHP使用“header("Last-Modified:".gmdate( "D,d M Y H:i:s") . "GMT");header("Cache-Control:no-cache,must-revalidate");”来清除缓存。

php清除浏览器缓存

今天在开发过程中遇到一个小问题,后台修改一本书的封面,上传图片后,由于浏览器的缓存导致修改之后,后台还是显示原先的封面,后来加入了两行代码搞定了这个问题。

header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" );

说明:

header() 函数向客户端发送原始的 HTTP 报头。

认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数

语法

header(string,replace,http_response_code)

PHP header 的7种用法

header('Location:'.$url); //Location和":"之间无空格。

header('content-type:text/html;charset=utf-8');

header('HTTP/1.1 404 Not Found');

header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳转。

header("Expires: Mon, 26 Jul 1997 05: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");

header('HTTP/1.1 401 Unauthorized');header('WWW-Authenticate: Basic realm="Top Secret"');

header('Content-Type: application/octet-stream'); //设置内容类型header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件header('Content-Transfer-Encoding: binary'); //设置传输方式header('Content-Length: '.filesize('example.zip')); //设置内容长度

感谢你能够认真阅读完这篇文章,希望小编分享php清除浏览器缓存的方法内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!