PHP 常用的header頭部定義

來源:互聯網
上載者:User
  1. header('HTTP/1.1 200 OK'); // ok 正常訪問
  2. header('HTTP/1.1 404 Not Found'); //通知瀏覽器 頁面不存在
  3. header('HTTP/1.1 301 Moved Permanently'); //設定地址被永久的重新導向 301
  4. header('Location: http://www.ithhc.cn/'); //跳轉到一個新的地址
  5. header('Refresh: 10; url=http://www.ithhc.cn/'); //延遲轉向 也就是隔幾秒跳轉
  6. header('X-Powered-By: PHP/6.0.0'); //修改 X-Powered-By資訊
  7. header('Content-language: en'); //文檔語言
  8. header('Content-Length: 1234'); //設定內容長度
  9. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告訴瀏覽器最後一次修改時間
  10. header('HTTP/1.1 304 Not Modified'); //告訴瀏覽器文檔內容沒有發生改變
  11. ###內容類型###
  12. header('Content-Type: text/html; charset=utf-8'); //網頁編碼
  13. header('Content-Type: text/plain'); //純文字格式
  14. header('Content-Type: image/jpeg'); //JPG、JPEG
  15. header('Content-Type: application/zip'); // ZIP檔案
  16. header('Content-Type: application/pdf'); // PDF檔案
  17. header('Content-Type: audio/mpeg'); // 音頻檔案
  18. header('Content-type: text/css'); //css檔案
  19. header('Content-type: text/javascript'); //js檔案
  20. header('Content-type: application/json'); //json
  21. header('Content-type: application/pdf'); //pdf
  22. header('Content-type: text/xml'); //xml
  23. header('Content-Type: application/x-shockw**e-flash'); //Flash動畫
  24. ######
  25. ###聲明一個下載的檔案###
  26. header('Content-Type: application/octet-stream');
  27. header('Content-Disposition: attachment; filename="ITblog.zip"');
  28. header('Content-Transfer-Encoding: binary');
  29. readfile('test.zip');
  30. ######
  31. ###對當前文檔禁用緩衝###
  32. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
  33. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  34. ######
  35. ###顯示一個需要驗證的登陸對話方塊###
  36. header('HTTP/1.1 401 Unauthorized');
  37. header('WWW-Authenticate: Basic realm="Top Secret"');
  38. ######
  39. ###聲明一個需要下載的xls檔案###
  40. header('Content-Disposition: attachment; filename=ithhc.xlsx');
  41. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  42. header('Content-Length: '.filesize('./test.xls'));
  43. header('Content-Transfer-Encoding: binary');
  44. header('Cache-Control: must-revalidate');
  45. header('Pragma: public');
  46. readfile('./test.xls');
  47. ######
  48. ?>
複製代碼
PHP, header
  • 聯繫我們

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