這篇文章給大家分享的是PHP中header函數(shù)的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,下文將介紹header函數(shù)的作用、用法和應用示例這些,文中示例代碼介紹的非常詳細,感興趣的朋友接下來一起跟隨小編看看吧。
PHP的header函數(shù)是最常用的函數(shù)之一,用于向客戶端發(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://zhujib.com’);
其他常用的Header用法:
// Header永久性重定向,一般301與header Location一起使用.
header(‘HTTP/1.1 301 Moved Permanently'); header(‘Location: http://zhujib.com/');
// Header延時刷新頁面
//與HTML頁面中的<meta http-equiv=”refresh” content=”10;http://zhujib.com” />效果一樣 header(‘Refresh: 10; url=http://zhujib.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函數(shù)的作用和用法就介紹到這,上述示例具有一定的借鑒價值,感興趣的朋友可以參考,希望能對大家有幫助,想要了解更多PHP函數(shù)的內(nèi)容,大家可以關注其它的相關文章。