首頁  >  文章  >  後端開發  >  php中header的用法有哪些

php中header的用法有哪些

coldplay.xixi
coldplay.xixi原創
2020-09-07 10:52:485653瀏覽
php中header的用法有:1、跳到頁面;2、宣告content-type;3、回傳response狀態碼;4、在某個時間後執行跳躍;5、控制瀏覽器快取;6、執行http驗證。

php中header的用法有哪些

相關學習推薦:php程式設計(影片)

##php header的用法是:

1. 跳頁

header('Location:'.$url);  //Location和":"之间无空格

#2. 宣告content-type

header('content-type:text/html;charset=utf-8');

##3. 返回response狀態碼

header('HTTP/1.1 404 Not Found');

4. 在某個時間後執行跳躍

#

header('Refresh: 10; url=http://www.baidu.com/');  //10s后跳转

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. 執行 http 驗證

header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');

7.執行下載作業

header('Content-Type: application/octet-stream'); //设置内容类型
header('Content-Disposition: attachment; filename="example.zip"'); //设置MIME用户作为附件
header('Content-Transfer-Encoding: binary'); //设置传输方式
header('Content-Length: '.filesize('example.zip')); //设置内容长度
## 想了解更多程式學習,請關注

php培訓
欄位!

#

以上是php中header的用法有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn