PHP header 的用法

1. 跳轉頁面
  1. header('Location:'.$url);  //Location和":"之間無空格。
2. 聲明content-type
  1. header('content-type:text/html;charset=utf-8');
3. 返回response狀態碼
  1. header('HTTP/1.1 404 Not Found');
4. 在某個時間後執行跳轉
  1. header('Refresh: 10; url=http://www.baidu.com/');  //10s後跳轉。
5. 控制瀏覽器緩存
  1. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  2. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
  3. header("Cache-Control: no-cache, must-revalidate");
  4. header("Pragma: no-cache");
6. 執行http驗證
  1. header('HTTP/1.1 401 Unauthorized');
  2. header('WWW-Authenticate: Basic realm="Top Secret"');
7. 執行下載操作
  1. header('Content-Type: application/octet-stream'); //設置內容類型
  2. header('Content-Disposition: attachment; filename="example.zip"'); //設置MIME用戶作爲附件
  3. header('Content-Transfer-Encoding: binary'); //設置傳輸方式
  4. header('Content-Length: '.filesize('example.zip')); //設置內容長度

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章