PHP之header函式詳解

2022-09-25 22:48:13 字數 1090 閱讀 9536

php的header函式是最常用的函式之一,用於向客戶端傳送http頭資訊。

通過的用法如設定編碼、傳送http狀態值以及重定向。

上述兩個例子分別是設定utf8編碼和傳送404狀態。

header重定向:

header(『location: ');

其他常用的header用法:

// header永久性重定向,一般301與header location一起使用.

// header延時重新整理頁面

//與html頁面中的效果一樣

header(『refresh: 10; url=/');

// header設定頁面語言

header(程式設計客棧『content-language: en');

// 對於**頁面,可以宣告檔案型別和檔名

header(『contentwww.cppcns.com-type: application/oct');

header(『content-disposition: attachment; filename=」filename.zip」『);

header(『content-transfer-encoding: binary');

// header設定快取和快取過期時間

header(『cache-control: no-cache, no-store, max-age=0, must-revalidate');

hea程式設計客棧der(『expires: mon, 26 jul 1997 05:00:00 gmt');

// header設定頁面編碼:

header(『content-type: text/html; charset=utf-8′);

header函式詳解

php 3,php 4,php 5 header 傳送乙個原始 http 標頭 可選引數 replace 指明是替換掉前一條類似的標頭還是增加一條相同型別的標頭。預設為替換,但如果將其設為false則可以強制傳送多個同類標頭。例如 header www authenticate negotiate ...

每天乙個PHP函式之 header

header 函式向客戶端傳送原始的 http 報頭。認識到一點很重要,即必須在任何實際的輸出被傳送之前呼叫 header 函式 在 php 4 以及更高的版本中,可以使用輸出快取來解決此問題 結果出錯 在呼叫 header 之前已存在輸出header location header string,...

php中header函式的使用

header http 1.0 400 bad request 返回400錯誤 header http 1.0 404 not found 返回404錯誤 header location http host uri extra 跳轉 設定nocache 過期 1。php header 函式 網上很多...