[php] 常用header

来源:互联网 发布:知乎匿名提问 编辑:程序博客网 时间:2024/06/12 06:17

开发常用的header的头

// 重定向跳转

header('Refresh: 10; url=http://www.baidu.com/');

// 301 永久重定向,记得在后面要加重定向地址 Location:$url

header('HTTP/1.1 301 Moved Permanently'); 

// 成功跳转

header('HTTP/1.1 200 OK');

// 设置一个404头

header('HTTP/1.1 404 Not Found');

// 跳转

header('Location: http://www.baidu.com/');

// 语言设置

header('Content-language: en');

// 告诉浏览器最后一次修改时间

$time = time() - 60; // or filemtime($fn), etcheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

// 告诉浏览器文档内容没有发生改变

header('HTTP/1.1 304 Not Modified');

// 下载

header("Content-Type:application/download");

// 强制下载

header("Content-Type:application/force-download");

// 设置头文件类型,可以用于流文件或者文件下载

header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="example.zip"'); header('Content-Transfer-Encoding: binary'); readfile('example.zip'); // 读取文件到客户端

// 附件

header('Content-type: application/pdf'); // 指定内容格式header('Content-Disposition: attachment; filename="downloaded.pdf"'); // 指定内容为附件readfile('original.pdf'); // 打开文件,并输出

// 禁用缓存

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 

// 设置内容长度

header('Content-Length: 39344');

// 设置页面头信息

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'); 

// 登录框

header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Basic realm="登录信息"'); echo '显示的信息!';

// 重写 X-Powered-By 值

header('X-Powered-By: PHP/5.3.0'); header('X-Powered-By: Brain/0.6b'); 

先写这么多,后期还会继续进行更新!
谢谢关注!

0 0
原创粉丝点击