PHP header 的幾種用法


 

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')); //設置內容長度

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM