PHP设置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设置http头信息的更多相关文章
- 在AngularJs中怎么设置请求头信息(headers)及不同方法的比较
在AngularJS中有三种方式可以设置请求头信息: 1.在http服务的在服务端发送请求时,也就是调用http()方法时,在config对象中设置请求头信息:事例如下: $http.post('/s ...
- 设置请求头信息User-Agent
设置请求头信息User-Agent来模拟浏览器. 先来看User-Agent: 当我们向服务器发送请求时,浏览器会将一些头信息附加上,然后发给服务器. 如上图所示头信息(请求头信息 Request H ...
- phpstorm设置方法头信息备注
一.目标,如下图,希望在方法上增加如下头信息备注 二.设置live template: 三.增加方法头信息备注,如下所示: * created by ${USER} at ${DATE} ${TIME ...
- 设置response头信息禁止缓存
java代码中可通过如下代码设置 response.setHeader("Pragma", "No-Cache"); response.setHeader(&q ...
- jquery ajax请求时,设置请求头信息
设置一个名为 headers 的参数 参考代码: // attempt to make an XMLHttpRequest to indeed.com // jQuery 1.6.1 and Chro ...
- JQuery Ajax 设置请求头信息application/json
今天有个api后台接application/json格式的 在Jquery里$.ajax默认是contentType: application/x-www-form-urlencoded; chars ...
- 动手学servlet(三) 请求头和响应头信息
获取请求头信息 package servletdemo; import java.io.IOException; import java.util.Enumeration; import javax. ...
- ajax中的setRequestHeader设置请求头
1.问题引发点: 前不久发现一个问题: 前端并没有设置请求头信息里面的Accept-Encoding:gzip...但是在请求头中可以明显的看到Accept-Encoding:gzip, deflat ...
- HttpServletResponse ServletResponse 返回响应 设置响应头设置响应正文体 重定向 常用方法 如何重定向 响应编码 响应乱码
HttpServletResponse 和 ServletResponse 都是接口 具体的类型对象是由Servlet容器传递过来 ServletResponse对象的功能分为以下四种: ...
随机推荐
- dedecms likearticle 调用附加表的字段调用方式
[field:id runphp='yes'] $aid = @me; $row = $GLOBALS['dsql']->GetOne("Select 字段名 From `dede_a ...
- Taum and B'day
//自己 def main(): t = int(raw_input()) for _ in range(t): units = 0 b, w = map(int, raw_input().strip ...
- 最短路--hdu2544
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Java 网络编程---分布式文件协同编辑器设计与实现
目录: 第一部分:Java网络编程知识 (一)简单的Http请求 一般浏览网页时,使用的时Ip地址,而IP(Internet Protocol,互联网协议)目前主要是IPv4和IPv6. IP地址是一 ...
- linux安装xunsearch
首先要确保ubuntu安装了gcc g++ make sudo apt-get install make gcc g++ 然后安装zlib,用来解压的: apt-get install zlib1g- ...
- content的定义
http://www.myexception.cn/HTML-CSS/1472528.html http://stackoverflow.com/questions/2770681/css-conte ...
- poj3294 --Life Forms
Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12483 Accepted: 3501 Descr ...
- LeetCode_Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- IC封装图片认识(一):BGA
在上篇文章<常用IC封装技术介绍>第一个提到的IC封装形式就是BGA,全称是Ball Grid Array(球栅阵列结构的PCB),它是集成电路采用有机载板的一种封装法.其具有以下五个特点 ...
- DELL配置信息
CPU详情CPU厂商 英特尔CPU (英特尔)Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHzCPU核心数 2CPU默认频率 2400 MhzCPU外频 533 MHz ...