PHP中header()函數(shù)的七種用法小結(jié)
PHP header()的7中用法:
1、跳轉(zhuǎn)頁面
可以使用header()實現(xiàn)跳轉(zhuǎn)頁面功能。
header('Location:'.$url); // $url 跳轉(zhuǎn)頁面的地址2、聲明 content-type
調(diào)用API接口時,一般都會聲明 content-type 的類型,否則無法讀寫數(shù)據(jù)。
header('content-type:text/html;charset=utf-8');
header('content-type:application/json;charset=utf-8');3、返回response狀態(tài)碼
header('HTTP/1.1 404 Not Found');4、定時執(zhí)行跳轉(zhuǎn)
header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳轉(zhuǎn)。在這里插入代碼片5、控制瀏覽器緩存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");6、執(zhí)行http驗證
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');7、下載
header('Content-Type: application/octet-stream'); //設(shè)置內(nèi)容類型
header('Content-Disposition: attachment; filename="example.zip"'); //設(shè)置MIME用戶作為附件
header('Content-Transfer-Encoding: binary'); //設(shè)置傳輸方式
header('Content-Length: '.filesize('example.zip')); //設(shè)置內(nèi)容長度到此這篇關(guān)于PHP中header()的七種用法小結(jié)的文章就介紹到這了,更多相關(guān)PHP header()用法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
php在多維數(shù)組中根據(jù)鍵名快速查詢其父鍵以及父鍵值的代碼
有一個多維數(shù)組,有多少維大家可以自定義。假如我們要在這個數(shù)組中找一個鍵為'subIndex'的值,我們可以用for、foreach等方法遍歷查找 反過來,假如我們?nèi)我饨o出一個或多個鍵,要求找出這個鍵的父級數(shù)組的鍵和值。這又如何實現(xiàn)?2011-05-05
解析php中的fopen()函數(shù)用打開文件模式說明
PHP中使用數(shù)組實現(xiàn)堆棧數(shù)據(jù)結(jié)構(gòu)的代碼
PHP5.5.15+Apache2.4.10+MySQL5.6.20配置方法分享
PHP框架Laravel插件Pagination實現(xiàn)自定義分頁

