PHP uses the header function to set various HTTP header examples

Source: Internet
Author: User
  1. /**
  2. Desc:header functions to set various HTTP headers
  3. link:bbs.it-home.org
  4. Date:2013/2/24
  5. */
  6. Defining 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 OK ');
  28. Set a 404 Header:
  29. Header (' http/1.1 404 Not Found ');
  30. Set 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 Steering:
  35. Header (' refresh:10; url=http://bbs.it-home.org/');
  36. print ' You'll be redirected in ten seconds ';
  37. Of course, you can also use HTML syntax to implement
  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, Jul 1997 05:00:00 GMT '); Date in the past
  45. Header (' Pragma:no-cache ');
  46. To set the 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 files
  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 would be displayed if the user hits cancel or ';
  59. print ' enters wrong login data ';
  60. ?>
Copy Code
  • Related Article

    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.