php header有哪些意思
发布时间:09/01 来源:未知 浏览:
关键词:
header函数在PHP中是发送一些头部信息的, 我们可以直接使用它来做301跳转等,下面我来总结关于header函数用途与一些常用见问题解决办法。
发送一个原始 HTTP 标头[Http Header]到客户端。标头 (header) 是效劳器以 HTTP 协义传 HTML 材料到阅读器前所送出的字串,在标头与 HTML 文件之间尚需空一行分隔.
1.重定向.
Header("Location: http://www.mobiletrain.org");
exit; //在每个重定向之后都必需加上“exit”,幸免发生错误后,连续施行。
2.制止页面在IE中缓存
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-store, no-cache, must-revalidate' ); header( 'Cache-Control: post-check=0, pre-check=0', false ); header( 'Pragma: no-cache' ); //兼容http1.0和https
3.实现文件下载
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'));//设定内容长度 readfile('example.zip');//读取需要下载的文件
4. 向阅读器发送Status标头
header(”Status: 404 Not Found”);
但是我发明实际上阅读器返回的响应却是:
// ok header(‘HTTP/1.1 200 OK’); //设定一个404头: header(‘HTTP/1.1 404 Not Found’); //设定地址被永远的重定向 header(‘HTTP/1.1 301 Moved Permanently’); HTTP/1.x 200 OK Date: Thu, 03 Aug 2006 07:49:11 GMT Server: Apache/2.0.55 (Win32)php/5.0.5 X-Powered-By: PHP/5.0.5 Status: 404 Not Found Content-Length: 0 Keep-Alive: timeout=15, max=98 Connection: Keep-Alive Content-Type: text/html 留意事项有以下几点.
Location和”:”之间不克不及有空格,不然会显现错误(注释:我刚测试了,在我当地环境下,没有跳转页面,但是也没有报错,不分明什么缘由);
在用header前不克不及有任何的输出(注释:这点大家都知道的,假如header此前有任何的输出,包罗空白,就会显现header already sent by xxx的错误);
header 后面的东西还会施行的。
引荐:《PHP教程》
以上就是php header是啥意思的具体内容,更多请关注百分百源码网其它相关文章!