>  기사  >  백엔드 개발  >  php header函数使用实例代码_PHP教程

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

WBOY
WBOY원래의
2016-07-13 17:41:27871검색

  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...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.