您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php header是什么意思

2024/4/13 6:38:06发布28次查看
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”);
但是我发现实际上浏览器返回的响应却是:
// okheader(‘http/1.1 200 ok’);//设置一个404头:header(‘http/1.1 404 not found’);//设置地址被永久的重定向header(‘http/1.1 301 moved permanently’);http/1.x 200 okdate: thu, 03 aug 2006 07:49:11 gmtserver: apache/2.0.55 (win32)php/5.0.5x-powered-by: php/5.0.5status: 404 not foundcontent-length: 0keep-alive: timeout=15, max=98connection: keep-alivecontent-type: text/html注意事项有以下几点.
location和”:”之间不能有空格,否则会出现错误(注释:我刚测试了,在我本地环境下,没有跳转页面,但是也没有报错,不清楚什么原因);
在用header前不能有任何的输出(注释:这点大家都知道的,如果header之前有任何的输出,包括空白,就会出现header already sent by xxx的错误);
header 后面的东西还会执行的。
推荐:《php教程》
以上就是php header是什么意思的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product