Example of setting various HTTP headers using the header function in php

Source: Internet
Author: User
Example of setting various HTTP headers using the header function in php

  1. /**
  2. Desc: header function to set various HTTP headers
  3. Link: bbs.it-home.org
  4. Date:
  5. */
  6. // Define the 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 delay redirection:
  35. Header ('refresh: 10; url = http://bbs.it-home.org /');
  36. Print 'You will be redirected in 10 seconds ';
  37. // Of course, you can also use html syntax to implement
  38. // Header ('content-Transfer-Encoding: binary ');
  39. // Load the file to send:
  40. Readfile('example.zip ');
  41. // Disable caching for the current document
  42. Header ('cache-Control: no-Cache, no-store, max-age = 0, must-revalidate ');
  43. Header ('expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  44. Header ('pragma: no-cache ');
  45. // Set the content type:
  46. Header ('content-Type: text/html; charset = ISO-8859-1 ');
  47. Header ('content-Type: text/html; charset = utf-8 ');
  48. Header ('content-Type: text/plain '); // plain text format
  49. Header ('content-Type: image/jpeg '); // JPG ***
  50. Header ('content-Type: application/zip'); // zip file
  51. Header ('content-Type: application/pdf '); // pdf file
  52. Header ('content-Type: audio/mpeg '); // audio File
  53. Header ('content-Type: application/x-shockw ** e-Flash'); // flash animation
  54. // Display the login dialog box
  55. Header ('http/1.1 401 unauthorized ');
  56. Header ('www-Authenticate: Basic realm = "Top Secret "');
  57. Print 'text that will be displayed if the user hits cancel or ';
  58. Print 'enters wrong login data ';
  59. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.