PHP的header函數是最常用的函數之一,用于向客戶端發(fā)送HTTP頭信息。
通過的用法如設置編碼、發(fā)送HTTP狀態(tài)值以及重定向。
php header utf8 :
header(“Content-type: text/html; charset=utf-8″);
php header 404 :
header(“HTTP/1.0 404 Not Found”);
上述兩個例子分別是設置UTF8編碼和發(fā)送404狀態(tài)。
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.com” />效果一樣 header(‘Refresh: 10; url=http://www.phpthinking.com/');
// Header設置頁面語言
header(‘Content-language: en');
// 對于下載頁面,可以聲明文件類型和文件名
header(‘Content-Type: application/octet-stream'); 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'); header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Header設置頁面編碼:
header(‘Content-Type: text/html; charset=utf-8′);
到此這篇關于PHP之header函數詳解的文章就介紹到這了,更多相關PHP之header函數內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
下一篇:Git命令之分支詳解