Home > Backend Development > PHP Tutorial > Examples of php using the header function to set various HTTP headers

Examples of php using the header function to set various HTTP headers

WBOY
Release: 2016-07-25 09:04:39
Original
1005 people have browsed it
  1. /**
  2. desc: header function sets various HTTP headers
  3. link: bbs.it-home.org
  4. date: 2013/2/24
  5. */
  6. //Define encoding
  7. header( 'Content-Type: text/html;charset=utf-8 ');
  8. //Atom
  9. header ('Content-type: application/atom+xml');
  10. //CSS
  11. header('Content-type: text/css');
  12. //Javascript
  13. header('Content-type: text/javascript' );
  14. //JPEG Image
  15. header('Content-type: image/jpeg');
  16. //JSON
  17. header('Content-type: application/json');
  18. //PDF
  19. header(' Content-type: application/pdf');
  20. //RSS
  21. header('Content-Type: application/rss+xml; charset=ISO-8859-1');
  22. //Text (Plain)
  23. header( 'Content-type: text/plain');
  24. //XML
  25. header('Content-type: text/xml');
  26. // ok
  27. header('HTTP/1.1 200 OK');
  28. / /Set a 404 header:
  29. header('HTTP/1.1 404 Not Found');
  30. //Set the address to be permanently redirected
  31. header('HTTP/1.1 301 Moved Permanently');
  32. //Go to a New address
  33. header('Location: http://bbs.it-home.org/');
  34. //File delayed redirection:
  35. header('Refresh: 10; url=http://bbs.it-home .org/');
  36. print 'You will be redirected in 10 seconds';
  37. //Of course, it can also be implemented using html syntax
  38. //
  39. header('Content-Transfer-Encoding: binary');
  40. // load the file to send:
  41. readfile('example.zip');
  42. // Disable caching for the current document
  43. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate') ;
  44. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  45. header('Pragma: no-cache');
  46. //Set content type:
  47. header( 'Content-Type: text/html; charset=iso-8859-1');
  48. header('Content-Type: text/html; charset=utf-8');
  49. header('Content-Type: text/plain '); //Plain text format
  50. header('Content-Type: image/jpeg'); //JPG***
  51. header('Content-Type: application/zip'); // ZIP file
  52. header(' Content-Type: application/pdf'); // PDF file
  53. header('Content-Type: audio/mpeg'); // Audio file
  54. header('Content-Type: application/x-shockw**e-flash '); //Flash animation
  55. //Show login dialog box
  56. header('HTTP/1.1 401 Unauthorized');
  57. header('WWW-Authenticate: Basic realm="Top Secret"');
  58. print 'Text that will be displayed if the user hits cancel or ';
  59. print 'enters wrong login data';
  60. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template