1. 程式人生 > 程式設計 >PHP之header函式詳解

PHP之header函式詳解

php的header函式是最常程式設計客棧用的函式之一,用於向客戶端傳送HTTP頭資訊。

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

php header utf8 :

header(“Content-type: texthttp://www.cppcns.com/html; charset=utf-8″);

php header 404 :

header(“HTTP/1.0 404 Not Found”);

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

header重定向:

header(‘Location: http://www.phpthinking.com');

其他常用的Header用法:

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

header(‘HTTP/1.1 301 Moved Permanently');
header(‘Location: http://www.phpthinking.com/');

// Header延時重新整理頁面

//與HTML頁面中的<meta http-equiv=”refresh” content=”10;http://www.phpthinking.http://www.cppcns.comcom” />效果一樣
header(‘Refresh: 10; url=http://www.phpthinking.com/');

// Header設定頁面語言

header(‘Content-language: en');

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

header(‘Content-Type: application/octet-stream');
header(‘CocNfhkDuDrPntent-Disposition: attachment; filename=”filename.zip”‘);
header(‘Content-Transfer-Encoding: binary');

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

header(‘Cache-Control: no-cache,no-store,max-age=0,must-rehttp://www.cppcns.com
validate'); header(‘Expires: Mon,26 Jul 1997 05:00:00 GMT');

// Header設定頁面編碼:

header(‘Content-Type: text/html; charset=utf-8′);

到此這篇關於PHP之header函式詳解的文章就介紹到這了,更多相關PHP之header函式內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!