Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php header是什么意思

php header是什么意思

发布时间:2020-11-26   编辑:www.jquerycn.cn
jquery中文网为您提供php header是什么意思等资源,欢迎您收藏本站,我们将为您提供最新的php header是什么意思资源

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是什么意思的详细内容,更多请关注jquery中文网其它相关文章!

  • 本文原创发布jQuery中文网,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    php header是什么意思
    HTML5中的header标签是什么意思?HTML5中header标签具体使用方法你知道吗?
    自动跳转url的php代码是什么
    php 解决各种应用的乱码问题
    python中的%是什么意思
    PHP 页面编码声明方法详解(header或meta)
    html5 header标签是什么意思?html5 header标签的用法详解(附实例)
    php中解决各种应用的乱码问题
    php $$是什么意思
    php .=是什么意思

    上一篇:怎么打开php网页 下一篇:php时间戳转换
    [关闭]