1. <?PHP
  2. function https($num) {
  3. $http = array (
  4. 100 => "HTTP/1.1 100 Continue",
  5. 101 => "HTTP/1.1 101 Switching Protocols",
  6. 200 => "HTTP/1.1 200 OK",
  7. 201 => "HTTP/1.1 201 Created",
  8. 202 => "HTTP/1.1 202 Accepted",
  9. 203 => "HTTP/1.1 203 Non-Authoritative Information",
  10. 204 => "HTTP/1.1 204 No Content",
  11. 205 => "HTTP/1.1 205 Reset Content",
  12. 206 => "HTTP/1.1 206 Partial Content",
  13. 300 => "HTTP/1.1 300 Multiple Choices",
  14. 301 => "HTTP/1.1 301 Moved Permanently",
  15. 302 => "HTTP/1.1 302 Found",
  16. 303 => "HTTP/1.1 303 See Other",
  17. 304 => "HTTP/1.1 304 Not Modified",
  18. 305 => "HTTP/1.1 305 Use Proxy",
  19. 307 => "HTTP/1.1 307 Temporary Redirect",
  20. 400 => "HTTP/1.1 400 Bad Request",
  21. 401 => "HTTP/1.1 401 Unauthorized",
  22. 402 => "HTTP/1.1 402 Payment Required",
  23. 403 => "HTTP/1.1 403 Forbidden",
  24. 404 => "HTTP/1.1 404 Not Found",
  25. 405 => "HTTP/1.1 405 Method Not Allowed",
  26. 406 => "HTTP/1.1 406 Not Acceptable",
  27. 407 => "HTTP/1.1 407 Proxy Authentication Required",
  28. 408 => "HTTP/1.1 408 Request Time-out",
  29. 409 => "HTTP/1.1 409 Conflict",
  30. 410 => "HTTP/1.1 410 Gone",
  31. 411 => "HTTP/1.1 411 Length Required",
  32. 412 => "HTTP/1.1 412 Precondition Failed",
  33. 413 => "HTTP/1.1 413 Request Entity Too Large",
  34. 414 => "HTTP/1.1 414 Request-URI Too Large",
  35. 415 => "HTTP/1.1 415 Unsupported Media Type",
  36. 416 => "HTTP/1.1 416 Requested range not satisfiable",
  37. 417 => "HTTP/1.1 417 Expectation Failed",
  38. 500 => "HTTP/1.1 500 Internal Server Error",
  39. 501 => "HTTP/1.1 501 Not Implemented",
  40. 502 => "HTTP/1.1 502 Bad Gateway",
  41. 503 => "HTTP/1.1 503 Service Unavailable",
  42. 504 => "HTTP/1.1 504 Gateway Time-out"
  43. );
  44. header($http[$num]);
  45. };
  46. //200 正常状态
  47. header('HTTP/1.1 200 OK');
  48. // 301 永久重定向,记得在后面要加重定向地址 Location:$url
  49. header('HTTP/1.1 301 Moved Permanently');
  50. // 重定向,其实就是302 暂时重定向
  51. header('Location: http://www.xxxx.com/');
  52. // 设置页面304 没有修改
  53. header('HTTP/1.1 304 Not Modified');
  54. // 显示登录框,
  55. header('HTTP/1.1 401 Unauthorized');
  56. header('WWW-Authenticate: Basic realm="登录信息"');
  57. echo '显示的信息!';
  58. // 403 禁止访问
  59. header('HTTP/1.1 403 Forbidden');
  60. // 404 错误
  61. header('HTTP/1.1 404 Not Found');
  62. // 500 服务器错误
  63. header('HTTP/1.1 500 Internal Server Error');
  64. // 3秒后重定向指定地址(也就是刷新到新页面与 <meta http-equiv="refresh" content="10;http://www.xxxx.com/ /> 相同)
  65. header('Refresh: 3; url=http://www.xxxx.com/');
  66. echo '10后跳转到http://www.xxxx.com';
  67. // 重写 X-Powered-By 值
  68. header('X-Powered-By: PHP/5.3.0');
  69. header('X-Powered-By: Brain/0.6b');
  70. //设置上下文语言
  71. header('Content-language: en');
  72. // 设置页面最后修改时间(多用于防缓存)
  73. $time = time() - 60; //建议使用filetime函数来设置页面缓存时间
  74. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
  75. // 设置内容长度
  76. header('Content-Length: 39344');
  77. // 设置头文件类型,可以用于流文件或者文件下载
  78. header('Content-Type: application/octet-stream');
  79. header('Content-Disposition: attachment; filename="example.zip"');
  80. header('Content-Transfer-Encoding: binary');
  81. readfile('example.zip');//读取文件到客户端
  82. //禁用页面缓存
  83. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  84. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  85. header('Pragma: no-cache');
  86. //设置页面头信息
  87. header('Content-Type: text/html; charset=iso-8859-1');
  88. header('Content-Type: text/html; charset=utf-8');
  89. header('Content-Type: text/plain');
  90. header('Content-Type: image/jpeg');
  91. header('Content-Type: application/zip');
  92. header('Content-Type: application/pdf');
  93. header('Content-Type: audio/mpeg');
  94. header('Content-Type: application/x-shockwave-flash');
  95. //.... 至于Content-Type 的值 可以去查查 w3c 的文档库,那里很丰富
  96. ?>

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. dedecms likearticle 调用附加表的字段调用方式

    [field:id runphp='yes'] $aid = @me; $row = $GLOBALS['dsql']->GetOne("Select 字段名 From `dede_a ...

  2. Taum and B'day

    //自己 def main(): t = int(raw_input()) for _ in range(t): units = 0 b, w = map(int, raw_input().strip ...

  3. 最短路--hdu2544

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. Java 网络编程---分布式文件协同编辑器设计与实现

    目录: 第一部分:Java网络编程知识 (一)简单的Http请求 一般浏览网页时,使用的时Ip地址,而IP(Internet Protocol,互联网协议)目前主要是IPv4和IPv6. IP地址是一 ...

  5. linux安装xunsearch

    首先要确保ubuntu安装了gcc g++ make sudo apt-get install make gcc g++ 然后安装zlib,用来解压的: apt-get install zlib1g- ...

  6. content的定义

    http://www.myexception.cn/HTML-CSS/1472528.html http://stackoverflow.com/questions/2770681/css-conte ...

  7. poj3294 --Life Forms

    Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12483   Accepted: 3501 Descr ...

  8. LeetCode_Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  9. IC封装图片认识(一):BGA

    在上篇文章<常用IC封装技术介绍>第一个提到的IC封装形式就是BGA,全称是Ball Grid Array(球栅阵列结构的PCB),它是集成电路采用有机载板的一种封装法.其具有以下五个特点 ...

  10. DELL配置信息

    CPU详情CPU厂商 英特尔CPU (英特尔)Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHzCPU核心数 2CPU默认频率 2400 MhzCPU外频 533 MHz ...