日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 PHP其他 正文

PHP中header()的七種用法

作者:L小臣 更新時(shí)間: 2023-08-30 PHP其他

我們?cè)趯?shí)際開發(fā)中經(jīng)常使用header()實(shí)現(xiàn)一些功能,這篇文章介紹關(guān)于header()的7中用法,需要的伙伴的開參考一下。
PHP header()的7中用法:

1、跳轉(zhuǎn)頁面

可以使用header()實(shí)現(xiàn)跳轉(zhuǎn)頁面功能。

header('Location:'.$url); // $url 跳轉(zhuǎn)頁面的地址

2、聲明 content-type

調(diào)用API接口時(shí),一般都會(huì)聲明 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、定時(shí)執(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驗(yàn)證


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)容長(zhǎng)度

原文鏈接:https://blog.csdn.net/weixin_44888397/article/details/132520961

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新