《PHP實例:PHP中Header使用的HTTP協議及常用方法小結》要點:
本文介紹了PHP實例:PHP中Header使用的HTTP協議及常用方法小結,希望對您有用。如果有疑問,可以聯系我們。
PHP編程本文實例總結了PHP中Header使用的HTTP協議及常用辦法.分享給大家供大家參考.具體辦法如下:
PHP編程//200 正常狀態
header('HTTP/1.1 200 OK');
PHP編程// 301 永久重定向,記得在后面要加重定向地址 Location:$url
header('HTTP/1.1 301 Moved Permanently');
PHP編程// 重定向,其實就是302 暫時重定向
header('Location: http://www.xxxx.com/');
PHP編程// 設置頁面304 沒有修改
header('HTTP/1.1 304 Not Modified');
PHP編程// 顯示登錄框,
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="登錄信息"');
echo '顯示的信息!';
PHP編程// 403 禁止拜訪
header('HTTP/1.1 403 Forbidden');
PHP編程// 404 錯誤
header('HTTP/1.1 404 Not Found');
PHP編程// 500 服務器錯誤
header('HTTP/1.1 500 Internal Server Error');
PHP編程// 3秒后重定向指定地址(也就是刷新到新頁面與 <meta http-equiv="refresh" content="10;http://www.xxxx.com/ /> 相同)
header('Refresh: 3; url=http://www.xxxx.com/');
echo '10后跳轉到http://www.xxxx.com';
PHP編程// 重寫 X-Powered-By 值
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b');
PHP編程//設置上下文語言
header('Content-language: en');
PHP編程// 設置頁面最后修改時間(多用于防緩存)
$time = time() - 60; //建議使用filetime函數來設置頁面緩存時間
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
PHP編程// 設置內容長度
header('Content-Length: 39344');
PHP編程// 設置頭文件類型,可以用于流文件或者文件下載
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
readfile('example.zip');//讀取文件到客戶端
PHP編程//禁用頁面緩存
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');
PHP編程//設置頁面頭信息
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編程希望本文所述對大家的PHP程序設計有所贊助.
《PHP實例:PHP中Header使用的HTTP協議及常用方法小結》是否對您有啟發,歡迎查看更多與《PHP實例:PHP中Header使用的HTTP協議及常用方法小結》相關教程,學精學透。維易PHP學院為您提供精彩教程。