php header函數使用執行個體代碼_PHP教程

來源:互聯網
上載者:User
  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. ?>

http://www.bkjia.com/PHPjc/486126.htmlwww.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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.