php header函数使用实例代码_PHP教程

WBOY
Freigeben: 2016-07-13 17:41:27
Original
871 Leute haben es durchsucht

  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...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage