這篇文章給大家分享的是PHP中header函數(shù)的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,下文將介紹header函數(shù)的作用、用法和應(yīng)用示例這些,文中示例代碼介紹的非常詳細(xì),感興趣的朋友接下來(lái)一起跟隨小編看看吧。
PHP的header函數(shù)是最常用的函數(shù)之一,用于向客戶(hù)端發(fā)送HTTP頭信息。通過(guò)的用法如設(shè)置編碼、發(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”);
上述兩個(gè)例子分別是設(shè)置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延時(shí)刷新頁(yè)面
//與HTML頁(yè)面中的<meta http-equiv=”refresh” content=”10;http://zhujib.com” />效果一樣 header(‘Refresh: 10; url=http://zhujib.com/');
// Header設(shè)置頁(yè)面語(yǔ)言
header(‘Content-language: en');
// 對(duì)于下載頁(yè)面,可以聲明文件類(lèi)型和文件名
header(‘Content-Type: application/octet-stream'); header(‘Content-Disposition: attachment; filename=”filename.zip”‘); header(‘Content-Transfer-Encoding: binary');
// Header設(shè)置緩存和緩存過(guò)期時(shí)間
header(‘Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Header設(shè)置頁(yè)面編碼:
header(‘Content-Type: text/html; charset=utf-8′);
關(guān)于PHP中header函數(shù)的作用和用法就介紹到這,上述示例具有一定的借鑒價(jià)值,感興趣的朋友可以參考,希望能對(duì)大家有幫助,想要了解更多PHP函數(shù)的內(nèi)容,大家可以關(guān)注其它的相關(guān)文章。