Home  >  Article  >  Backend Development  >  PHP header function usage example code_PHP tutorial

PHP header function usage example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:41:27839browse

  1. /*** Function: PHP header() examples (PHP)
  2. ** 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.
  3. ** Example: see below.

    Tip: You can use these sites to check your headers: web-sniffer.net, delorie.com or www.forret.com.
  4. ** Author: Jonas John
  5. */
  6. // fix 404 pages:
  7. header(HTTP/1.1 200 OK);
  8. // set 404 header:
  9. header(HTTP/1.1 404 Not Found);
  10. // set Moved Permanently header (good for redrictions)
  11. // use with location header
  12. header(HTTP/1.1 301 Moved Permanently);
  13. // redirect to a new location:
  14. header(Location: http://www.example.org/);
  15. // redrict with delay:
  16. header(Refresh: 10; url=http://www.example.org/);
  17. print You will be redirected in 10 seconds;
  18. // you could also use the HTML syntax://
  19. header(Content-Transfer-Encoding: binary);
  20. // load the file to send:readfile(example.zip);
  21. // Disable caching of the current document:
  22. header(Cache-Control: no-cache, no-store, max-age=0, must-revalidate);
  23. header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
  24. // Date in the pastheader(Pragma: no-cache);
  25. // set content type:
  26. header(Content-Type: text/html; charset=iso-8859-1);
  27. header(Content-Type: text/html; charset=utf-8);
  28. header(Content-Type: text/plain);
  29. // plain text file
  30. header(Content-Type: image/jpeg);
  31. // JPG picture
  32. header(Content-Type: application/zip);
  33. // ZIP file
  34. header(Content-Type: application/pdf);
  35. // PDF file
  36. header(Content-Type: audio/mpeg);
  37. // Audio MPEG (MP3,…) file
  38. header(Content-Type: application/x-shockwave-flash);
  39. // Flash animation// show sign in box
  40. header(HTTP/1.1 401 Unauthorized);
  41. header(WWW-Authenticate: Basic realm="Top Secret");
  42. print Text that will be displayed if the user hits cancel or ;
  43. print enters wrong login data;
  44. ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486126.htmlTechArticle?php /*** Function: PHP header() examples (PHP) ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.j...
Statement:
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