PHP header 的7种用法

跳转页面

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

声明content-type

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

返回response状态码

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

在某个时间后执行跳转

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

控制浏览器缓存

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");

执行http验证

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

执行下载操作

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

posted on   何苦->  阅读(107)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2018-05-13 javascript node节点学习

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示