<?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头信息的更多相关文章

  1. 在AngularJs中怎么设置请求头信息(headers)及不同方法的比较

    在AngularJS中有三种方式可以设置请求头信息: 1.在http服务的在服务端发送请求时,也就是调用http()方法时,在config对象中设置请求头信息:事例如下: $http.post('/s ...

  2. 设置请求头信息User-Agent

    设置请求头信息User-Agent来模拟浏览器. 先来看User-Agent: 当我们向服务器发送请求时,浏览器会将一些头信息附加上,然后发给服务器. 如上图所示头信息(请求头信息 Request H ...

  3. phpstorm设置方法头信息备注

    一.目标,如下图,希望在方法上增加如下头信息备注 二.设置live template: 三.增加方法头信息备注,如下所示: * created by ${USER} at ${DATE} ${TIME ...

  4. 设置response头信息禁止缓存

    java代码中可通过如下代码设置 response.setHeader("Pragma", "No-Cache"); response.setHeader(&q ...

  5. jquery ajax请求时,设置请求头信息

    设置一个名为 headers 的参数 参考代码: // attempt to make an XMLHttpRequest to indeed.com // jQuery 1.6.1 and Chro ...

  6. JQuery Ajax 设置请求头信息application/json

    今天有个api后台接application/json格式的 在Jquery里$.ajax默认是contentType: application/x-www-form-urlencoded; chars ...

  7. 动手学servlet(三) 请求头和响应头信息

    获取请求头信息 package servletdemo; import java.io.IOException; import java.util.Enumeration; import javax. ...

  8. ajax中的setRequestHeader设置请求头

    1.问题引发点: 前不久发现一个问题: 前端并没有设置请求头信息里面的Accept-Encoding:gzip...但是在请求头中可以明显的看到Accept-Encoding:gzip, deflat ...

  9. HttpServletResponse ServletResponse 返回响应 设置响应头设置响应正文体 重定向 常用方法 如何重定向 响应编码 响应乱码

    HttpServletResponse  和 ServletResponse  都是接口 具体的类型对象是由Servlet容器传递过来   ServletResponse对象的功能分为以下四种:   ...

随机推荐

  1. R语言数据处理

    写在前面:数据处理是数据分析与挖掘必不可少的步骤.下面列出一些常用的数据处理操作. 一.类型转换 用class()查看数据的类型,用as.类型名()进行类型转换. > num <- as. ...

  2. 函数:lambda表达式 - 零基础入门学习Python021

    函数:lambda表达式 让编程改变世界 Change the world by program lambda表达式 Python允许使用lambda关键字来创建匿名函数.我们提到一个新的关键字:匿名 ...

  3. Web模板大全

    http://www.dede58.com/a/free/ http://down.admin5.com/moban/109507.html http://www.chinaz.com/ http:/ ...

  4. haporxy 负载elasticsearch

    <pre name="code" class="html">-bash-4.1# cat /etc/haproxy/haproxy.cfg glob ...

  5. C#优秀开源资料收集

    1. 把对命令行程序的调用封装起来,通过程序里进行输入,调用命令行程序的输出显示在程序中 http://www.codeproject.com/Articles/335909/Embedding-a- ...

  6. repter导出到Excel

     ;                 ,  * );                 sheet1.SetColumnWidth(,  * );                 sheet1.SetC ...

  7. jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动

    jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动 http://www.17sucai.com/pins/demoshow/382

  8. Android之字符串的拆分-split

    字符串的拆分可以利用android的 split 来简单实现 具体看如下代码: String s3 = "Real-How-To"; String [] temp = null; ...

  9. ubuntu 14.04 下试用Sublime Text 3

    很多源代码都没有IDE支持的,尤其是开源的源代码.从github上下载的,很多也不用IDE.包括我自己公司的代码,基本都是脚本,也不用IDE.通常情况下,都是用notepad++.UE之类的文本编辑器 ...

  10. LitJson处理Json

    LitJSON是一个.NET平台下处理JSON格式数据的类库,小巧.快速.它的源代码使用C#编写,可以通过任何.Net平台上的语言进行调用,目前最新版本为LitJSON 0.9. 下载地址: http ...