zoukankan      html  css  js  c++  java
  • PHP 使用header函数设置HTTP头的示例方法 表头(转)

    1. //定义编码  
    2. header( 'Content-Type:text/html;charset=utf-8 ');  
    3.   
    4. //Atom  
    5. header('Content-type: application/atom+xml');  
    6.   
    7. //CSS  
    8. header('Content-type: text/css');  
    9.   
    10. //Javascript  
    11. header('Content-type: text/javascript');  
    12.   
    13. //JPEG Image  
    14. header('Content-type: image/jpeg');  
    15.   
    16. //JSON  
    17. header('Content-type: application/json');  
    18.   
    19. //PDF  
    20. header('Content-type: application/pdf');  
    21.   
    22. //RSS  
    23. header('Content-Type: application/rss+xml; charset=ISO-8859-1');  
    24.   
    25. //Text (Plain)  
    26. header('Content-type: text/plain');  
    27.   
    28. //XML  
    29. header('Content-type: text/xml');  
    30.   
    31. // ok  
    32. header('HTTP/1.1 200 OK');  
    33.   
    34. //设置一个404头:  
    35. header('HTTP/1.1 404 Not Found');  
    36.   
    37. //设置地址被永久的重定向  
    38. header('HTTP/1.1 301 Moved Permanently');  
    39.   
    40. //转到一个新地址  
    41. header('Location: http://www.example.org/');  
    42.   
    43. //文件延迟转向:  
    44. header('Refresh: 10; url=http://www.example.org/');  
    45. print 'You will be redirected in 10 seconds';  
    46.   
    47. //当然,也可以使用html语法实现  
    48. // <meta http-equiv="refresh" content="10;http://www.example.org/ />  
    49.   
    50. // override X-Powered-By: PHP:  
    51. header('X-Powered-By: PHP/4.4.0');  
    52. header('X-Powered-By: Brain/0.6b');  
    53.   
    54. //文档语言  
    55. header('Content-language: en');  
    56.   
    57. //告诉浏览器最后一次修改时间  
    58. $time = time() - 60; // or filemtime($fn), etc  
    59. header('Last-Modified: '.gmdate('D, d M Y H:i:s'$time).' GMT');  
    60.   
    61. //告诉浏览器文档内容没有发生改变  
    62. header('HTTP/1.1 304 Not Modified');  
    63.   
    64. //设置内容长度  
    65. header('Content-Length: 1234');  
    66.   
    67. //设置为一个下载类型  
    68. header('Content-Type: application/octet-stream');  
    69. header('Content-Disposition: attachment; filename="example.zip"');  
    70. header('Content-Transfer-Encoding: binary');  
    71. // load the file to send:  
    72. readfile('example.zip');  
    73.   
    74. // 对当前文档禁用缓存  
    75. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');  
    76. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past  
    77. header('Pragma: no-cache');  
    78.   
    79. //设置内容类型:  
    80. header('Content-Type: text/html; charset=iso-8859-1');  
    81. header('Content-Type: text/html; charset=utf-8');  
    82. header('Content-Type: text/plain'); //纯文本格式  
    83. header('Content-Type: image/jpeg'); //JPG***  
    84. header('Content-Type: application/zip'); // ZIP文件  
    85. header('Content-Type: application/pdf'); // PDF文件  
    86. header('Content-Type: audio/mpeg'); // 音频文件  
    87. header('Content-Type: application/x-shockw**e-flash'); //Flash动画  
    88.   
    89. //显示登陆对话框  
    90. header('HTTP/1.1 401 Unauthorized');  
    91. header('WWW-Authenticate: Basic realm="Top Secret"');  
    92. print 'Text that will be displayed if the user hits cancel or ';  
    93. print 'enters wrong login data';  
  • 相关阅读:
    微信小程序开发之初探
    C# 利用SharpPcap实现网络包捕获嗅探
    C# SharpMap的简单使用
    C# 实现中国象棋【棋盘,棋子】
    C# 实现FTP客户端
    C# 实现连连看功能
    C# 实现截图软件功能
    C# 利用PrintDocument定制打印单据
    驰骋工作流引擎设计系列05 启动流程设计
    驰骋工作流引擎设计系列04 流程引擎表结构的设计
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3069223.html
Copyright © 2011-2022 走看看