php header()函数的使用

 跳转页面html

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

 声明content-type浏览器

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

 返回response状态码缓存

header('HTTP/1.1 404 Not Found');复制代码

 在某个时间后执行跳转bash

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

五、控制浏览器缓存
app

名称 含义 示例
Expires 响应过时的日期和时间 Expires: Thu, 01 Dec 2010 16:00:00 GMT
Last-Modified 请求资源的最后修改时间 Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT
Cache-Control 告诉全部的缓存机制是否能够缓存及哪一种类型 Cache-Control: no-cache
Pragma 包括实现特定的指令,它可应用到响应链上的任何接收方 Pragma: no-cache
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验证url

名称 含义 示例
WWW-Authenticate 代表客户端请求实体应该使用的受权方案 WWW-Authenticate: Basic
header('HTTP/1.1 401 Unauthorized'); 
header('WWW-Authenticate: Basic realm="Top Secret"');

七、执行下载操做
spa

Content-Disposition 消息头指示回复的内容该以何种形式展现,是之内联的形式(即网页或者页面的一部分),仍是以附件的形式下载并保存到本地。 Content-Disposition: attachment; filename=”filename.jpg”

header('Content-Type: application/octet-stream'); //设置内容类型 header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户
.net

八、做为附件code

header('Content-Transfer-Encoding: binary'); //设置传输方式
header('Content-Length: '.filesize('example.zip')); //设置内容长度复制代码


转载:https://blog.csdn.net/change_any_time/article/details/79597500
htm