PHP中Header使用的HTTP协议及常用方法小结
发布:smiling 来源: PHP粉丝网 添加日期:2021-04-23 11:24:12 浏览: 评论:0
这篇文章主要介绍了PHP中Header使用的HTTP协议及常用方法,包含了各种错误编码类型及其含义,需要的朋友可以参考下
本文实例总结了PHP中Header使用的HTTP协议及常用方法。分享给大家供大家参考。具体方法如下:
- <?PHP
- function https($num) {
- $http = array (
- 100 => "HTTP/1.1 100 Continue",
- 101 => "HTTP/1.1 101 Switching Protocols",
- 200 => "HTTP/1.1 200 OK",
- 201 => "HTTP/1.1 201 Created",
- 202 => "HTTP/1.1 202 Accepted",
- 203 => "HTTP/1.1 203 Non-Authoritative Information",
- 204 => "HTTP/1.1 204 No Content",
- 205 => "HTTP/1.1 205 Reset Content",
- 206 => "HTTP/1.1 206 Partial Content",
- 300 => "HTTP/1.1 300 Multiple Choices",
- 301 => "HTTP/1.1 301 Moved Permanently",
- 302 => "HTTP/1.1 302 Found",
- 303 => "HTTP/1.1 303 See Other",
- 304 => "HTTP/1.1 304 Not Modified",
- 305 => "HTTP/1.1 305 Use Proxy",
- 307 => "HTTP/1.1 307 Temporary Redirect",
- 400 => "HTTP/1.1 400 Bad Request",
- 401 => "HTTP/1.1 401 Unauthorized",
- 402 => "HTTP/1.1 402 Payment Required",
- 403 => "HTTP/1.1 403 Forbidden",
- 404 => "HTTP/1.1 404 Not Found",
- 405 => "HTTP/1.1 405 Method Not Allowed",
- 406 => "HTTP/1.1 406 Not Acceptable",
- 407 => "HTTP/1.1 407 Proxy Authentication Required",
- 408 => "HTTP/1.1 408 Request Time-out",
- 409 => "HTTP/1.1 409 Conflict",
- 410 => "HTTP/1.1 410 Gone",
- 411 => "HTTP/1.1 411 Length Required",
- 412 => "HTTP/1.1 412 Precondition Failed",
- 413 => "HTTP/1.1 413 Request Entity Too Large",
- 414 => "HTTP/1.1 414 Request-URI Too Large",
- 415 => "HTTP/1.1 415 Unsupported Media Type",
- 416 => "HTTP/1.1 416 Requested range not satisfiable",
- 417 => "HTTP/1.1 417 Expectation Failed",
- 500 => "HTTP/1.1 500 Internal Server Error",
- 501 => "HTTP/1.1 501 Not Implemented",
- 502 => "HTTP/1.1 502 Bad Gateway",
- 503 => "HTTP/1.1 503 Service Unavailable",
- 504 => "HTTP/1.1 504 Gateway Time-out"
- );
- header($http[$num]);
- };
- //200 正常状态
- header('HTTP/1.1 200 OK');
- // 301 永久重定向,记得在后面要加重定向地址 Location:$url
- header('HTTP/1.1 301 Moved Permanently');
- // 重定向,其实就是302 暂时重定向
- header('Location: http://www.xxxx.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;http://www.xxxx.com/ /> 相同)
- header('Refresh: 3; url=http://www.xxxx.com/');
- echo '10后跳转到http://www.xxxx.com';
- // 重写 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 的文档库,那里很丰富
- ?>
希望本文所述对大家的PHP程序设计有所帮助。
Tags: Header HTTP协议
相关文章
- ·header 函式的使用(2013-11-27)
- ·php header中Content-disposition用法详细(2013-12-02)
- ·php Cannot modify header information-headers already sent by解决办法(2013-12-04)
- ·php header 404错误包含文件出现乱码(2013-12-04)
- ·php header中301/404跳转要注意事项详解(2014-01-11)
- ·php中header("Location:xxx.php")跳转问题(2014-01-19)
- ·php header 404跳转错误页面实例(2014-07-21)
- ·PHP Header下载文件在IE文件名中文乱码问题(2014-09-13)
- ·header() 301重定向实现代码(2014-09-18)
- ·php header函数输入图片IE不显示问题(2014-09-20)
- ·Fatal error: Call to undefined function get_header() in(2014-09-21)
- ·php header()函数实现文件下载的文件,提示被破坏不能打开(2014-09-21)
- ·php header请求重写的一个问题(2014-09-21)
- ·PHP利用header跳转失效解决方法(2014-09-22)
- ·直接用php的header发送404错误页面的方法实例(2015-04-09)
- ·PHP header常用URL地址跳转的几种方法(2015-04-11)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)