php header() 常用content-type
2019-10-11 本文已影响0人
xueyueshuai
1. //定义编码
2. header( 'Content-Type:text/html;charset=utf-8 ');
4. //Atom
5. header('Content-type: application/atom+xml');
7. //CSS
8. header('Content-type: text/css');
10. //Javascript
11. header('Content-type: text/javascript');
13. //JPEG Image
14. header('Content-type: image/jpeg');
16. //JSON
17. header('Content-type: application/json');
19. //PDF
20. header('Content-type: application/pdf');
22. //RSS
23. header('Content-Type: application/rss+xml; charset=ISO-8859-1');
25. //Text (Plain)
26. header('Content-type: text/plain');
28. //XML
29. header('Content-type: text/xml');
31. // ok
32. header('HTTP/1.1 200 OK');
34. //设置一个404头:
35. header('HTTP/1.1 404 Not Found');
37. //设置地址被永久的重定向
38. header('HTTP/1.1 301 Moved Permanently');
40. //转到一个新地址
41. header('Location: http://www.example.org/');
43. //文件延迟转向:
44. header('Refresh: 10; url=http://www.example.org/');
45. print 'You will be redirected in 10 seconds';
47. //当然,也可以使用html语法实现
48. // <meta http-equiv="refresh" content="10;http://www.example.org/ />
50. // override X-Powered-By: PHP:
51. header('X-Powered-By: PHP/4.4.0');
52. header('X-Powered-By: Brain/0.6b');
54. //文档语言
55. header('Content-language: en');
57. //告诉浏览器最后一次修改时间
58. $time = time() - 60; // or filemtime($fn), etc
59. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
61. //告诉浏览器文档内容没有发生改变
62. header('HTTP/1.1 304 Not Modified');
64. //设置内容长度
65. header('Content-Length: 1234');
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');
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');
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动画
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';
function msg($code, $msg = 'success', $data = [])
{
$code = (int) $code;
$msg = (string) $msg;
$data = (object) $data;
header("Access-Control-Expose-Headers:xzd-code");
header("Access-Control-Expose-Headers:xzd-msg");
header('xzd-code:' . $code);
header('xzd-msg:' . $msg);
// return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data], JSON_UNESCAPED_UNICODE);
return json(['code' => $code, 'msg' => Lang::get($msg), 'data' => $data]);
}