PHP常用header頭定義代碼示例匯總
在php的開(kāi)發(fā)中,我們常常需要使用到header函數(shù)頭來(lái)進(jìn)行做標(biāo)記
header() 函數(shù)向客戶(hù)端發(fā)送原始的 HTTP 報(bào)頭。
常用header設(shè)置列表如下:
header('HTTP/1.1 200 OK'); // ok 正常訪(fǎng)問(wèn)
header('HTTP/1.1 404 Not Found'); //通知瀏覽器 頁(yè)面不存在
header('HTTP/1.1 301 Moved Permanently'); //設(shè)置地址被永久的重定向 301
header('Location: http://www.ithhc.cn/'); //跳轉(zhuǎn)到一個(gè)新的地址
header('Refresh: 10; url=http://www.ithhc.cn/'); //延遲轉(zhuǎn)向 也就是隔幾秒跳轉(zhuǎn)
header('X-Powered-By: PHP/6.0.0'); //修改 X-Powered-By信息
header('Content-language: en'); //文檔語(yǔ)言
header('Content-Length: 1234'); //設(shè)置內(nèi)容長(zhǎng)度
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告訴瀏覽器最后一次修改時(shí)間
header('HTTP/1.1 304 Not Modified'); //告訴瀏覽器文檔內(nèi)容沒(méi)有發(fā)生改變
內(nèi)容類(lèi)型
header('Content-Type: text/html; charset=utf-8'); //網(wǎng)頁(yè)編碼
header('Content-Type: text/plain'); //純文本格式
header('Content-Type: image/jpeg'); //JPG、JPEG
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音頻文件
header('Content-type: text/css'); //css文件
header('Content-type: text/javascript'); //js文件
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml格式文件
header('Content-Type: application/x-shockw**e-flash'); //Flash動(dòng)畫(huà)
聲明一個(gè)下載的文件
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
對(duì)當(dāng)前文檔禁用緩存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
顯示一個(gè)需要驗(yàn)證的登陸對(duì)話(huà)框
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
聲明一個(gè)需要下載的xls文件
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls'));
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
readfile('./test.xls');
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ThinkPHP使用心得分享-上傳類(lèi)UploadFile的使用
ThinkPHP中的UploadFile類(lèi)用于處理文件上傳,本文小總結(jié)了一下關(guān)于學(xué)習(xí)過(guò)程中對(duì)UploadFile類(lèi)的使用方法。2014-05-05
php 多繼承的幾種常見(jiàn)實(shí)現(xiàn)方法示例
這篇文章主要介紹了php 多繼承的幾種常見(jiàn)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了兩種PHP實(shí)現(xiàn)多繼承的操作方法,需要的朋友可以參考下2019-11-11
win2003服務(wù)器使用WPS的COM組件的一些問(wèn)題解決方法
項(xiàng)目中使用了新功能,gump同學(xué)研究出來(lái)的使用WPS的COM組件用PHP實(shí)現(xiàn)將doc等office格式轉(zhuǎn)換成pdf2012-01-01
用PHP實(shí)現(xiàn)小寫(xiě)金額轉(zhuǎn)換大寫(xiě)金額的代碼(精確到分)
數(shù)字金額轉(zhuǎn)換成中文大寫(xiě)金額的函數(shù) String Int $num 要轉(zhuǎn)換的小寫(xiě)數(shù)字或小寫(xiě)字符串2012-01-01

