首页  >  文章  >  后端开发  >  PHP header头部定义详解

PHP header头部定义详解

小云云
小云云原创
2018-03-03 14:27:164226浏览

本文主要和大家分享PHP header头部定义详解,希望能帮助到大家。

<?php

header(&#39;HTTP/1.1 200 OK&#39;); // ok 正常访问

header(&#39;HTTP/1.1 404 Not Found&#39;); //通知浏览器 页面不存在

header(&#39;HTTP/1.1 301 Moved Permanently&#39;); //设置地址被永久的重定向 301

header(&#39;Location: http://www.ithhc.cn/&#39;); //跳转到一个新的地址

header(&#39;Refresh: 10; url=http://www.ithhc.cn/&#39;); //延迟转向 也就是隔几秒跳转

header(&#39;X-Powered-By: PHP/6.0.0&#39;); //修改 X-Powered-By信息

header(&#39;Content-language: en&#39;); //文档语言

header(&#39;Content-Length: 1234&#39;); //设置内容长度

header(&#39;Last-Modified: &#39;.gmdate(&#39;D, d M Y H:i:s&#39;, $time).&#39; GMT&#39;); //告诉浏览器最后一次修改时间

header(&#39;HTTP/1.1 304 Not Modified&#39;); //告诉浏览器文档内容没有发生改变

###内容类型###

header(&#39;Content-Type: text/html; charset=utf-8&#39;); //网页编码

header(&#39;Content-Type: text/plain&#39;); //纯文本格式

header(&#39;Content-Type: image/jpeg&#39;); //JPG、JPEG

header(&#39;Content-Type: application/zip&#39;); // ZIP文件

header(&#39;Content-Type: application/pdf&#39;); // PDF文件

header(&#39;Content-Type: audio/mpeg&#39;); // 音频文件

header(&#39;Content-type: text/css&#39;); //css文件

header(&#39;Content-type: text/javascript&#39;); //js文件

header(&#39;Content-type: application/json&#39;); //json

header(&#39;Content-type: application/pdf&#39;); //pdf

header(&#39;Content-type: text/xml&#39;); //xml

header(&#39;Content-Type: application/x-shockw**e-flash&#39;); //Flash动画

######

###声明一个下载的文件###

header(&#39;Content-Type: application/octet-stream&#39;);

header(&#39;Content-Disposition: attachment; filename="ITblog.zip"&#39;);

header(&#39;Content-Transfer-Encoding: binary&#39;);

readfile(&#39;test.zip&#39;);

######

###对当前文档禁用缓存###

header(&#39;Cache-Control: no-cache, no-store, max-age=0, must-revalidate&#39;);

header(&#39;Expires: Mon, 26 Jul 1997 05:00:00 GMT&#39;);

######

###显示一个需要验证的登陆对话框###

header(&#39;HTTP/1.1 401 Unauthorized&#39;);

header(&#39;WWW-Authenticate: Basic realm="Top Secret"&#39;);

######

###声明一个需要下载的xls文件###

header(&#39;Content-Disposition: attachment; filename=ithhc.xlsx&#39;);

header(&#39;Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&#39;);

header(&#39;Content-Length: &#39;.filesize(&#39;./test.xls&#39;));

header(&#39;Content-Transfer-Encoding: binary&#39;);

header(&#39;Cache-Control: must-revalidate&#39;);

header(&#39;Pragma: public&#39;);

readfile(&#39;./test.xls&#39;);

######

?>

相关推荐:

php中关于header头部定义的详解

PHP常用的header头部定义汇总

PHP 常用的header头部定义汇总_PHP

以上是PHP header头部定义详解的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn