php header功能的使用
更新時間:2013年10月28日 15:46:51 作者:
php header的使用,PHP常見header狀態(tài)總結。
header() 函數向客戶端發(fā)送原始的 HTTP 報頭。
復制代碼 代碼如下:
<?php
//200 正常狀態(tài)
header('HTTP/1.1 200 OK');
// 301 永久重定向,記得在后面要加重定向地址 Location:$url
header('HTTP/1.1 301 Moved Permanently');
// 重定向,其實就是302 暫時重定向
header('Location: http://www.maiyoule.com/');
// 設置頁面304 沒有修改
header('HTTP/1.1 304 Not Modified');
// 顯示登錄框,
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="登錄信息"');
echo '顯示的信息!';
// 403 禁止訪問
header('HTTP/1.1 403 Forbidden');
// 404 錯誤
header('HTTP/1.1 404 Not Found');
// 500 服務器錯誤
header('HTTP/1.1 500 Internal Server Error');
// 3秒后重定向指定地址(也就是刷新到新頁面與 <meta http-equiv="refresh" content="10;http://chabaoo.cn/ /> 相同)
header('Refresh: 3; url=http://chabaoo.cn/');
echo '10后跳轉到http://chabaoo.cn';
// 重寫 X-Powered-By 值
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b');
//設置上下文語言
header('Content-language: en');
// 設置頁面最后修改時間(多用于防緩存)
$time = time() - 60; //建議使用filetime函數來設置頁面緩存時間
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 設置內容長度
header('Content-Length: 39344');
// 設置頭文件類型,可以用于流文件或者文件下載
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
readfile('example.zip');//讀取文件到客戶端
//禁用頁面緩存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Pragma: no-cache');
//設置頁面頭信息
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');
header('Content-Type: image/jpeg');
header('Content-Type: application/zip');
header('Content-Type: application/pdf');
header('Content-Type: audio/mpeg');
header('Content-Type: application/x-shockwave-flash');
//.... 至于Content-Type 的值 可以去查查 w3c 的文檔庫,那里很豐富
?>
您可能感興趣的文章:
- php出現Cannot modify header information問題的解決方法大全
- php header()函數使用說明
- PHP Header用于頁面跳轉要注意的幾個問題總結
- php利用header函數實現文件下載時直接提示保存
- php session_start()關于Cannot send session cache limiter - headers already sent錯誤解決方法
- PHP 頁面編碼聲明方法詳解(header或meta)
- PHP下利用header()函數設置瀏覽器緩存的代碼
- php header Content-Type類型小結
- PHP header()函數使用詳細(301、404等錯誤設置)
- php中get_headers函數的作用及用法的詳細介紹
- 探討php中header的用法詳解
- PHP 使用header函數設置HTTP頭的示例解析 表頭
- 淺析php header 跳轉
- php用header函數實現301跳轉代碼實例
- PHP錯誤Warning: Cannot modify header information - headers already sent by解決方法
- PHP使用header()輸出圖片緩存實例
- PHP 常用的header頭部定義匯總
相關文章
fleaphp crud操作之findByField函數的使用方法
fleaphp crud操作之findByField函數的用法分享,需要的朋友可以參考下。2011-04-04PHP mail 通過Windows的SMTP發(fā)送郵件失敗的解決方案
今天調試WordPress的郵件發(fā)送功能,總是提示:SMTP server response: 501 5.5.4 Invalid Address。用telnet測試SMTP是沒有任何問題的2009-05-05