php使用“header(last-modified:.gmdate( d,d m y h:i:s) . gmt);header(cache-control:no-cache,must-revalidate);”来清除缓存。
推荐:《php视频教程》
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种用法1. 跳转页面header('location:'.$url); //location和":"之间无空格。
2. 声明content-typeheader('content-type:text/html;charset=utf-8');
3. 返回response状态码header('http/1.1 404 not found');
4. 在某个时间后执行跳转header('refresh: 10; url=http://www.baidu.com/'); //10s后跳转。
5. 控制浏览器缓存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");
6. . 执行http验证header('http/1.1 401 unauthorized');header('www-authenticate: basic realm="top secret"');
7. 执行下载操作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如何清除浏览器缓存?的详细内容。