這篇文章將為大家詳細講解有關PHP中header怎么使用,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
< ?
header('HTTP/1.1 200 OK'); // ok 正常訪問
header('HTTP/1.1 404 Not Found'); //通知瀏覽器 頁面不存在
header('HTTP/1.1 301 Moved Permanently'); //設置地址被永久的重定向 301
header('Location: http://www.ithhc.cn/'); //跳轉(zhuǎn)到一個新的地址
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'); //文檔語言
header('Content-Length: 1234'); //設置內(nèi)容長度
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告訴瀏覽器最后一次修改時間
header('HTTP/1.1 304 Not Modified'); //告訴瀏覽器文檔內(nèi)容沒有發(fā)生改變
###內(nèi)容類型###
header('Content-Type: text/html; charset=utf-8'); //網(wǎng)頁編碼
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動畫
######
###聲明一個下載的文件###
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="ITblog.zip"');
header('Content-Transfer-Encoding: binary');
readfile('test.zip');
######
###對當前文檔禁用緩存###
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
######
###顯示一個需要驗證的登陸對話框###
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
######
###聲明一個需要下載的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');
######
?>
關于PHP header()的7種用法 ,有著一定的參考價值,現(xiàn)在分享給大家,有需要的朋友可以參考一下
1. 跳轉(zhuǎn)頁面
1header('Location:'.$url); //Location和":"之間無空格。
2. 聲明content-type
1header('content-type:text/html;charset=utf-8');
3. 返回response狀態(tài)碼
1header('HTTP/1.1 404 Not Found');
4. 在某個時間后執(zhí)行跳轉(zhuǎn)
1header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳轉(zhuǎn)。
5. 控制瀏覽器緩存
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
6.執(zhí)行http驗證
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
7.執(zhí)行下載操作
header('Content-Type: application/octet-stream'); //設置內(nèi)容類型
header('Content-Disposition: attachment; filename="example.zip"'); //設置MIME用戶作為附件
header('Content-Transfer-Encoding: binary'); //設置傳輸方式
header('Content-Length: '.filesize('example.zip')); //設置內(nèi)容長度
關于PHP中header怎么使用就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)站標題:PHP中header怎么使用-創(chuàng)新互聯(lián)
URL標題:http://chinadenli.net/article36/djposg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站營銷、動態(tài)網(wǎng)站、軟件開發(fā)、App設計、網(wǎng)頁設計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容