php header功能的使用
更新時(shí)間:2013年10月28日 15:46:51 作者:
php header的使用,PHP常見header狀態(tài)總結(jié)。
header() 函數(shù)向客戶端發(fā)送原始的 HTTP 報(bào)頭。
復(fù)制代碼 代碼如下:
<?php
//200 正常狀態(tài)
header('HTTP/1.1 200 OK');
// 301 永久重定向,記得在后面要加重定向地址 Location:$url
header('HTTP/1.1 301 Moved Permanently');
// 重定向,其實(shí)就是302 暫時(shí)重定向
header('Location: http://www.maiyoule.com/');
// 設(shè)置頁面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 錯(cuò)誤
header('HTTP/1.1 404 Not Found');
// 500 服務(wù)器錯(cuò)誤
header('HTTP/1.1 500 Internal Server Error');
// 3秒后重定向指定地址(也就是刷新到新頁面與 <meta http-equiv="refresh" content="10;http://www.dbjr.com.cn/ /> 相同)
header('Refresh: 3; url=http://www.dbjr.com.cn/');
echo '10后跳轉(zhuǎn)到http://www.dbjr.com.cn';
// 重寫 X-Powered-By 值
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b');
//設(shè)置上下文語言
header('Content-language: en');
// 設(shè)置頁面最后修改時(shí)間(多用于防緩存)
$time = time() - 60; //建議使用filetime函數(shù)來設(shè)置頁面緩存時(shí)間
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 設(shè)置內(nèi)容長(zhǎng)度
header('Content-Length: 39344');
// 設(shè)置頭文件類型,可以用于流文件或者文件下載
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');
//設(shè)置頁面頭信息
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 的文檔庫(kù),那里很豐富
?>
您可能感興趣的文章:
- php出現(xiàn)Cannot modify header information問題的解決方法大全
- php header()函數(shù)使用說明
- PHP Header用于頁面跳轉(zhuǎn)要注意的幾個(gè)問題總結(jié)
- php利用header函數(shù)實(shí)現(xiàn)文件下載時(shí)直接提示保存
- php session_start()關(guān)于Cannot send session cache limiter - headers already sent錯(cuò)誤解決方法
- PHP 頁面編碼聲明方法詳解(header或meta)
- PHP下利用header()函數(shù)設(shè)置瀏覽器緩存的代碼
- php header Content-Type類型小結(jié)
- PHP header()函數(shù)使用詳細(xì)(301、404等錯(cuò)誤設(shè)置)
- php中g(shù)et_headers函數(shù)的作用及用法的詳細(xì)介紹
- 探討php中header的用法詳解
- PHP 使用header函數(shù)設(shè)置HTTP頭的示例解析 表頭
- 淺析php header 跳轉(zhuǎn)
- php用header函數(shù)實(shí)現(xiàn)301跳轉(zhuǎn)代碼實(shí)例
- PHP錯(cuò)誤Warning: Cannot modify header information - headers already sent by解決方法
- PHP使用header()輸出圖片緩存實(shí)例
- PHP 常用的header頭部定義匯總
相關(guān)文章
php數(shù)字每三位加逗號(hào)的功能函數(shù)
這篇文章主要介紹了php數(shù)字每三位加逗號(hào)的功能函數(shù),想知道如何做到數(shù)字每三位加逗號(hào)的朋友可以參考下2015-10-10PHP取整數(shù)函數(shù)常用的四種方法小結(jié)
PHP取整數(shù)函數(shù)常用的四種方法,下面收集了四個(gè)函數(shù);經(jīng)常用到取整的函數(shù),今天小小的總結(jié)一下!其實(shí)很簡(jiǎn)單,就是幾個(gè)函數(shù)而已~~主要是:ceil,floor,round,intval2012-07-07php實(shí)現(xiàn)子字符串位置相互對(duì)調(diào)互換的方法
這篇文章主要介紹了php實(shí)現(xiàn)子字符串位置相互對(duì)調(diào)互換的方法,可實(shí)現(xiàn)簡(jiǎn)單字符串中兩個(gè)子字符串互換的功能,涉及php字符串運(yùn)算與插入、替換等操作的相關(guān)技巧,需要的朋友可以參考下2016-06-06PHP 偽靜態(tài)技術(shù)原理以及突破原理實(shí)現(xiàn)介紹
偽靜態(tài)技術(shù)比較好突破,需要自己構(gòu)造中轉(zhuǎn)注入頁面;偽靜態(tài)技術(shù)原理都很簡(jiǎn)單,就是把原來的 index.php?id=1 這種形式的URL給替換成其它形式2013-07-07fleaphp crud操作之findByField函數(shù)的使用方法
fleaphp crud操作之findByField函數(shù)的用法分享,需要的朋友可以參考下。2011-04-04PHP mail 通過Windows的SMTP發(fā)送郵件失敗的解決方案
今天調(diào)試WordPress的郵件發(fā)送功能,總是提示:SMTP server response: 501 5.5.4 Invalid Address。用telnet測(cè)試SMTP是沒有任何問題的2009-05-05PHP英文字母大小寫轉(zhuǎn)換函數(shù)小結(jié)
這篇文章主要介紹了幾個(gè)PHP英文字母大小寫轉(zhuǎn)換函數(shù),分為首字母大小寫轉(zhuǎn)換和所有字母大小寫轉(zhuǎn)換,需要的朋友可以參考下2014-05-05