欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP中header()函數(shù)的七種用法小結(jié)

 更新時間:2023年08月29日 11:47:59   作者:L小臣  
我們在實際開發(fā)中經(jīng)常使用header()實現(xiàn)一些功能,這篇文章介紹關(guān)于header()的7中用法,文中有詳細(xì)的代碼示例,具有一定的參考價值,需要的朋友可以參考下

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)文章

最新評論