国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

基于header的一些常用指令詳解

2024-05-04 23:08:58
字體:
供稿:網(wǎng)友

header常用指令
header分為三部分:
第一部分為HTTP協(xié)議的版本(HTTP-Version);
第二部分為狀態(tài)代碼(Status);
第三部分為原因短語(Reason-Phrase)。

// fix 404 pages: 用這個header指令來解決URL重寫產(chǎn)生的404 header
header('HTTP/1.1 200 OK');

// set 404 header: 頁面沒找到
header('HTTP/1.1 404 Not Found');

//頁面被永久刪除,可以告訴搜索引擎更新它們的urls
// set Moved Permanently header (good for redrictions)
// use with location header
header('HTTP/1.1 301 Moved Permanently');

// 訪問受限
header('HTTP/1.1 403 Forbidden');

// 服務(wù)器錯誤
header('HTTP/1.1 500 Internal Server Error');

// 重定向到一個新的位置
// redirect to a new location:
header('Location: ');

延遲一段時間后重定向
// redrict with delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';

// 覆蓋 X-Powered-By value
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');

// 內(nèi)容語言 (en = English)
// content language (en = English)
header('Content-language: en');

//最后修改時間(在緩存的時候可以用到)
// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');

// 告訴瀏覽器要獲取的內(nèi)容還沒有更新
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');

// 設(shè)置內(nèi)容的長度 (緩存的時候可以用到):
// set content length (good for caching):
header('Content-Length: 1234');

// 用來下載文件:
// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');

// 禁止緩存當(dāng)前文檔:
// load the file to send:readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

// 設(shè)置內(nèi)容類型:
// Date in the pastheader('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');

// plain text file
header('Content-Type: image/jpeg');

// JPG picture
header('Content-Type: application/zip');

// ZIP file
header('Content-Type: application/pdf');

// PDF file
header('Content-Type: audio/mpeg');

// Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash');

// 顯示登錄對話框,可以用來進(jìn)行HTTP認(rèn)證
// Flash animation// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';

print 'enters wrong login data';?>

// 發(fā)送一個200 正常響應(yīng)
header("HTTP/1.1 200 OK");

// 發(fā)送一個404 找不到資源響應(yīng)
header('HTTP/1.1 404 Not Found');

// 發(fā)送一個301 永久重定向
header('HTTP/1.1 301 Moved Permanently');

// 發(fā)送一個503 網(wǎng)站暫時不能訪問
header('HTTP/1.1 503 Service Temporarily Unavailable');

// 網(wǎng)頁重定向
header('Location: ');

// 設(shè)置網(wǎng)頁3秒后重定向
header('Refresh: 3; url=http://www.survivalescaperooms.com');
echo '網(wǎng)頁將在3秒后跳轉(zhuǎn)到';

// 設(shè)置網(wǎng)頁編碼
header('Content-Type: text/html; charset=utf-8');

// 設(shè)置網(wǎng)頁輸出一個圖片流
header('Content-Type: image/jpeg');

// 設(shè)置網(wǎng)頁輸出一個pdf文檔
header('Content-Type: application/pdf');

// 設(shè)置網(wǎng)頁輸出一個zip文檔
header('Content-Type: application/zip');

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 萨嘎县| 德化县| 绍兴市| 遂川县| 皋兰县| 浦县| 辰溪县| 交口县| 庆元县| 蓝山县| 师宗县| 平度市| 肇庆市| 揭阳市| 封开县| 山东省| 穆棱市| 定兴县| 城固县| 凤山县| 福贡县| 余干县| 鄂温| 佛教| 灌南县| 民权县| 玛曲县| 文化| 苍山县| 会东县| 陇川县| 临邑县| 房山区| 柳江县| 长治市| 新巴尔虎左旗| 芒康县| 噶尔县| 益阳市| 白水县| 孟连|