Php header functions use instance code

Source: Internet
Author: User

  1. <? Php
  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/> <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. // Fix 404 pages:
  8. Header (HTTP/1.1 200 OK );
  9. // Set 404 header:
  10. Header (HTTP/1.1 404 Not Found );
  11. // Set Moved Permanently header (good for redrictions)
  12. // Use with location header
  13. Header (HTTP/1.1 301 Moved Permanently );
  14. // Redirect to a new location:
  15. Header (Location: http://www.example.org /);
  16. // Redrict with delay:
  17. Header (Refresh: 10; url = http://www.example.org /);
  18. Print You will be redirected in 10 seconds;
  19. // You cocould also use the HTML syntax: // <meta http-equiv = "refresh" content = "10; http://www.example.org //>
  20. // Override X-Powered-By: PHP:
  21. Header (X-Powered-By: PHP/4.4.0 );
  22. Header (X-Powered-By: Brain/0.6b );
  23. // Content language (en = English)
  24. Header (Content-language: en );
  25. // Last modified (good for caching)
  26. $ Time = time ()-60; // or filemtime ($ fn), etc
  27. Header (Last-Modified:. gmdate (D, d m y h: I: s, $ time). GMT );
  28. // Header for telling the browser that the content
  29. // Did not get changed
  30. Header (HTTP/1.1 304 Not Modified );
  31. // Set content length (good for caching ):
  32. Header (Content-Length: 1234 );
  33. // Headers for an download:
  34. Header (Content-Type: application/octet-stream );
  35. Header (Content-Disposition: attachment; filename = "example.zip ");
  36. Header (Content-Transfer-Encoding: binary );
  37. // Load the file to send: readfile(example.zip );
  38. // Disable caching of the current document:
  39. Header (Cache-Control: no-cache, no-store, max-age = 0, must-revalidate );
  40. Header (Expires: Mon, 26 Jul 1997 05:00:00 GMT );
  41. // Date in the pastheader (Pragma: no-cache );
  42. // Set content type:
  43. Header (Content-Type: text/html; charset = iso-8859-1 );
  44. Header (Content-Type: text/html; charset = UTF-8 );
  45. Header (Content-Type: text/plain );
  46. // Plain text file
  47. Header (Content-Type: image/jpeg );
  48. // JPG picture
  49. Header (Content-Type: application/zip );
  50. // ZIP file
  51. Header (Content-Type: application/pdf );
  52. // PDF file
  53. Header (Content-Type: audio/mpeg );
  54. // Audio MPEG (MP3 ,...) File
  55. Header (Content-Type: application/x-shockwave-flash );
  56. // Flash animation // show sign in box
  57. Header (HTTP/1.1 401 Unauthorized );
  58. Header (WWW-Authenticate: Basic realm = "Top Secret ");
  59. Print Text that will be displayed if the user hits cancel or;
  60. Print enters wrong login data;
  61. ?>

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.