php使用header函數設定各種HTTP頭的例子

來源:互聯網
上載者:User
  1. /**
  2. desc:header函數設定各種HTTP頭
  3. link:bbs.it-home.org
  4. date:2013/2/24
  5. */
  6. //定義編碼
  7. header( 'Content-Type:text/html;charset=utf-8 ');
  8. //Atom
  9. header('Content-type: application/atom+xml');
  10. //CSS
  11. header('Content-type: text/css');
  12. //Javascript
  13. header('Content-type: text/javascript');
  14. //JPEG Image
  15. header('Content-type: image/jpeg');
  16. //JSON
  17. header('Content-type: application/json');
  18. //PDF
  19. header('Content-type: application/pdf');
  20. //RSS
  21. header('Content-Type: application/rss+xml; charset=ISO-8859-1');
  22. //Text (Plain)
  23. header('Content-type: text/plain');
  24. //XML
  25. header('Content-type: text/xml');
  26. // ok
  27. header('HTTP/1.1 200 OK');
  28. //設定一個404頭:
  29. header('HTTP/1.1 404 Not Found');
  30. //設定地址被永久的重新導向
  31. header('HTTP/1.1 301 Moved Permanently');
  32. //轉到一個新地址
  33. header('Location: http://bbs.it-home.org/');
  34. //檔案延遲轉向:
  35. header('Refresh: 10; url=http://bbs.it-home.org/');
  36. print 'You will be redirected in 10 seconds';
  37. //當然,也可以使用html文法實現
  38. // header('Content-Transfer-Encoding: binary');
  39. // load the file to send:
  40. readfile('example.zip');
  41. // 對當前文檔禁用緩衝
  42. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  43. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  44. header('Pragma: no-cache');
  45. //設定內容類型:
  46. header('Content-Type: text/html; charset=iso-8859-1');
  47. header('Content-Type: text/html; charset=utf-8');
  48. header('Content-Type: text/plain'); //純文字格式
  49. header('Content-Type: image/jpeg'); //JPG***
  50. header('Content-Type: application/zip'); // ZIP檔案
  51. header('Content-Type: application/pdf'); // PDF檔案
  52. header('Content-Type: audio/mpeg'); // 音頻檔案
  53. header('Content-Type: application/x-shockw**e-flash'); //Flash動畫
  54. //顯示登陸對話方塊
  55. header('HTTP/1.1 401 Unauthorized');
  56. header('WWW-Authenticate: Basic realm="Top Secret"');
  57. print 'Text that will be displayed if the user hits cancel or ';
  58. print 'enters wrong login data';
  59. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.