久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

php之header的不同用法總結(jié)(實(shí)例講解)

下面小編就為大家分享一篇php之header的不同用法總結(jié)(實(shí)例講解),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

1、header()函數(shù)的作用是:發(fā)送一個原始 HTTP 標(biāo)頭[Http Header]到客戶端。

header(string,replace,http_response_code) 
/*string:必需。規(guī)定要發(fā)送的報頭字符串。
 replace:可選。指示該報頭是否替換之前的報頭,或添加第二個報頭。
 默認(rèn)是 true(替換)。false(允許相同類型的多個報頭)。
 http_response_code:可選。把 HTTP 響應(yīng)代碼強(qiáng)制為指定的值。*/

注意:必須在任何實(shí)際的輸出被發(fā)送之前調(diào)用 header() 函數(shù)。

2、 用法1:跳轉(zhuǎn)頁面

header("Location:https://baidu.com"); //正常跳轉(zhuǎn)
header('Refresh: 3; url=https://www.baidu.com'); //3s后跳轉(zhuǎn)
//在header作跳轉(zhuǎn)時,避免發(fā)生錯誤后,代碼繼續(xù)執(zhí)行,一般加個exit;

用法2:聲明content-type(我經(jīng)常拿來決解亂碼)

header('content-type:text/html;charset=utf-8');

用法3:返回響應(yīng)狀態(tài)碼

header('HTTP/1.1 403 Forbidden');

用法4:執(zhí)行下載操作(隱藏文件的位置)

header('Content-Type: application/octet-stream'); //設(shè)置內(nèi)容類型
header('Content-Disposition: attachment; filename="example.zip"');//設(shè)置MIME用戶作為附件
header('Content-Transfer-Encoding: binary'); //設(shè)置傳輸方式
header('Content-Length: '.filesize('example.zip')); //設(shè)置內(nèi)容長度

用法5:控制瀏覽器緩存

header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); //如果服務(wù)器上的網(wǎng)頁經(jīng)常變化,就把它設(shè)置為-1,表示立即過期
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );

用法6:

3、更多實(shí)例

<?php
// ok
header('HTTP/1.1 200 OK');
//設(shè)置一個404頭:
header('HTTP/1.1 404 Not Found');
//設(shè)置地址被永久的重定向
header('HTTP/1.1 301 Moved Permanently');
//轉(zhuǎn)到一個新地址
header('Location: http://www.example.org/');
//文件延遲轉(zhuǎn)向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
//當(dāng)然,也可以使用html語法實(shí)現(xiàn)
// <meta http-equiv="refresh" content="10;http://www.example.org/ />
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
//文檔語言
header('Content-language: en');
//告訴瀏覽器最后一次修改時間
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
//告訴瀏覽器文檔內(nèi)容沒有發(fā)生改變
header('HTTP/1.1 304 Not Modified');
//設(shè)置內(nèi)容長度
header('Content-Length: 1234');
//設(shè)置為一個下載類型
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"'); 
header('Content-Transfer-Encoding: binary');
// load the file to send:
readfile('example.zip');
// 對當(dāng)前文檔禁用緩存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
//設(shè)置內(nèi)容類型:
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'); //JPG圖片
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音頻文件
header('Content-Type: application/x-shockwave-flash'); //Flash動畫
//顯示登陸對話框
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';
?>

以上這篇php之header的不同用法總結(jié)(實(shí)例講解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持。

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

主站蜘蛛池模板: 久久草在线视频 | 国产乱码久久久久久一区二区 | 国产一区欧美 | 亚洲人成一区二区三区性色 | 日本三级电影在线看 | 日韩三级| 玖玖在线免费视频 | 91麻豆精品一区二区三区 | 欧美午夜视频 | 北条麻妃国产九九九精品小说 | 亚洲成年在线 | 久久久久国产精品午夜一区 | 国产精品99久久久久久久久久久久 | 久久乐国产精品 | 久久国产成人精品国产成人亚洲 | 国产黄色在线观看 | 仙人掌旅馆在线观看 | 视频国产一区 | 欧美一级免费观看 | 一级高清 | 一级片av| 成年视频在线观看福利资源 | 综合色在线 | 日本中文字幕一区 | 亚洲视频免费播放 | 日韩一区二区av | 国产99久久久国产精品 | 日本久久一区二区三区 | 亚洲午夜久久久 | 美女精品一区 | 九九av| 国产成人精品一区 | 涩涩视频在线看 | 中文在线播放 | 亚洲欧洲一区 | 亚洲国产精品一区 | 欧美一区二区三区在线看 | 国产不卡一区 | a国产一区二区免费入口 | 国产jizz女人多喷水99 | 日韩精品一区二区三区在线观看 |