Home  >  Article  >  php教程  >  一些常用php的header头

一些常用php的header头

PHP中文网
PHP中文网Original
2016-05-26 08:19:261026browse

一些常用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.ruonu.com/&#39;); //跳转到一个新的地址
header(&#39;Refresh: 10; url=http://www.ruonu.com/&#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中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php随机抽奖Next article:最新国内手机号码匹配