void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) : Send a raw HTTP header
下面有一些使用header的几种用法:
1、使用header函数进行跳转页面;
header('Location:'.$url);
其中$url就是将要跳转的url了。
这种用法的注意事项有以下几点:
":"之间不能有空格,否则会出现错误(注释:我刚测试了,在我本地环境下,没有跳转页面,但是也没有报错,不清楚什么原因);
"Refresh: {$delay}; url={$url}");
其中$delay就是推迟跳转的时间,$url为需要跳转的url
例如:header('Refresh: 10; url=http://www.example.org/'); 意思为10s后跳转到http://www.eexample.org这个网站
5、使用header控制浏览器缓存
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进行下载操作
header('Content-Type: application/octet-stream');//设置内容类型 header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件下载 如果将attachment换成inline意思为在线打开 header('Content-Transfer-Encoding: binary');//设置传输方式 header('Content-Length: '.filesize('example.zip'));//设置内容长度 // load the file to send: readfile('example.zip');//读取需要下载的文件
下面再给大家介绍PHP header 的几种用法
跳转页面
header('Location:'.$url); //Location和":"之间无空格。
声明content-type
header('content-type:text/html;charset=utf-8');
返回response状态码
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");
执行http验证
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')); //设置内容长度
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 谭咏麟.2000-魅力千禧演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 纯音入心系列纯音乐《器乐古筝》1CD[MP3][239MB]
- 纯音入心系列纯音乐《华夏民乐之古筝篇》1CD[MP3][192MB]
- 纯音入心系列纯音乐《中央民族乐团-古筝传奇》1CD[MP3][253.1MB]
- 江玲.1989-这样你才爱我,是吗?【新作有声】【WAV+CUE】
- 郭美美.2010-我是郭美美【华纳】【WAV+CUE】
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】