1. 2. /*** Function: PHP header() examples (PHP)
3. ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
4. ** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>.
5. ** Author: Jonas John
6. */
7.
8. // fix 404 pages:
9. header('HTTP/1.1 200 OK');
10.
11. // set 404 header:
12. header('HTTP/1.1 404 Not Found');
13.
14. // set Moved Permanently header (good for redrictions)
15. // use with location header
16. header('HTTP/1.1 301 Moved Permanently');
17.
18. // redirect to a new location:
19. header('Location: http://www.example.org/');
20.
21. // redrict with delay:
22. header('Refresh: 10; url=http://www.example.org/');
23. print 'You will be redirected in 10 seconds';
24.
25. // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />
26.
27. // override X-Powered-By: PHP:
28. header('X-Powered-By: PHP/4.4.0');
29. header('X-Powered-By: Brain/0.6b');
30.
31. // content language (en = English)
32. header('Content-language: en');
33.
34. // last modified (good for caching)
35. $time = time() - 60; // or filemtime($fn), etc
36. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
37.
38. // header for telling the browser that the content
39. // did not get changed
40. header('HTTP/1.1 304 Not Modified');
41.
42. // set content length (good for caching):
43. header('Content-Length: 1234');
44.
45. // Headers for an download:
46. header('Content-Type: application/octet-stream');
47. header('Content-Disposition: attachment; filename="example.zip"');
48. header('Content-Transfer-Encoding: binary');
49.
50. // load the file to send:readfile('example.zip');
51. // Disable caching of the current document:
52. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
53. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
54. // Date in the pastheader('Pragma: no-cache');
55. // set content type:
56. header('Content-Type: text/html; charset=iso-8859-1');
57. header('Content-Type: text/html; charset=utf-8');
58. header('Content-Type: text/plain');
59.
60. // plain text file
61. header('Content-Type: image/jpeg');
62.
63. // JPG picture
64. header('Content-Type: application/zip');
65.
66. // ZIP file
67. header('Content-Type: application/pdf');
68.
69. // PDF file
70. header('Content-Type: audio/mpeg');
71.
72. // Audio MPEG (MP3,...) file
73. header('Content-Type: application/x-shockwave-flash');
74.
75. // Flash animation// show sign in box
76. header('HTTP/1.1 401 Unauthorized');
77. header('WWW-Authenticate: Basic realm="Top Secret"');
78. print 'Text that will be displayed if the user hits cancel or ';
79. print 'enters wrong login data';?>
没有评论:
发表评论