当前位置: 移动技术网 > IT编程>开发语言>PHP > php header功能的使用

php header功能的使用

2019年04月03日  | 移动技术网IT编程  | 我要评论
header() 函数向客户端发送原始的 http 报头。复制代码 代码如下:<?php//200 正常状态header('http/1.1 200 ok');//

header() 函数向客户端发送原始的 http 报头。

复制代码 代码如下:

<?php
//200 正常状态
header('http/1.1 200 ok');
// 301 永久重定向,记得在后面要加重定向地址 location:$url
header('http/1.1 301 moved permanently');
// 重定向,其实就是302 暂时重定向
header('location: http://www.maiyoule.com/');
// 设置页面304 没有修改
header('http/1.1 304 not modified');
// 显示登录框,
header('http/1.1 401 unauthorized');
header('www-authenticate: basic realm="登录信息"');
echo '显示的信息!';
// 403 禁止访问
header('http/1.1 403 forbidden');
// 404 错误
header('http/1.1 404 not found');
// 500 服务器错误
header('http/1.1 500 internal server error');
// 3秒后重定向指定地址(也就是刷新到新页面与 <meta http-equiv="refresh" content="10;//www.jb51.net/ /> 相同)
header('refresh: 3; url=//www.jb51.net/');
echo '10后跳转到//www.jb51.net';
// 重写 x-powered-by 值
header('x-powered-by: php/5.3.0');
header('x-powered-by: brain/0.6b');
//设置上下文语言
header('content-language: en');
 // 设置页面最后修改时间(多用于防缓存)
$time = time() - 60; //建议使用filetime函数来设置页面缓存时间
header('last-modified: '.gmdate('d, d m y h:i:s', $time).' gmt');
// 设置内容长度
header('content-length: 39344');
// 设置头文件类型,可以用于流文件或者文件下载
header('content-type: application/octet-stream');
header('content-disposition: attachment; filename="example.zip"');
header('content-transfer-encoding: binary');
readfile('example.zip');//读取文件到客户端

//禁用页面缓存
header('cache-control: no-cache, no-store, max-age=0, must-revalidate');
header('expires: mon, 26 jul 1997 05:00:00 gmt');
header('pragma: no-cache');

//设置页面头信息
header('content-type: text/html; charset=iso-8859-1');
header('content-type: text/html; charset=utf-8');
header('content-type: text/plain');
header('content-type: image/jpeg');
header('content-type: application/zip');
header('content-type: application/pdf');
header('content-type: audio/mpeg');
header('content-type: application/x-shockwave-flash');
//.... 至于content-type 的值 可以去查查 w3c 的文档库,那里很丰富
?>

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网