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

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

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

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

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

注意:必須在任何實際的輸出被發送之前調用 header() 函數。

2、 用法1:跳轉頁面

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

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

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

用法3:返回響應狀態碼

header('HTTP/1.1 403 Forbidden');

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

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

用法5:控制瀏覽器緩存

header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); //如果服務器上的網頁經常變化,就把它設置為-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、更多實例

<?php
// ok
header('HTTP/1.1 200 OK');
//設置一個404頭:
header('HTTP/1.1 404 Not Found');
//設置地址被永久的重定向
header('HTTP/1.1 301 Moved Permanently');
//轉到一個新地址
header('Location: http://www.example.org/');
//文件延遲轉向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
//當然,也可以使用html語法實現
// <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');
//告訴瀏覽器文檔內容沒有發生改變
header('HTTP/1.1 304 Not Modified');
//設置內容長度
header('Content-Length: 1234');
//設置為一個下載類型
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');
// 對當前文檔禁用緩存
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');
//設置內容類型:
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的不同用法總結(實例講解)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持。

【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

主站蜘蛛池模板: 三级视频在线 | 自拍偷拍一区二区三区 | 免费中文字幕 | 天天精品视频 | 色多多视频在线观看 | 欧美成人精品欧美一级乱黄 | 欧美性受xxxx黑人xyx性爽 | 久久精品视频网 | 日韩免费在线观看视频 | 日韩中文字幕第一页 | 色综合久久久久 | 夜夜嗨av一区二区三区网页 | 97视频在线观看免费 | 水蜜桃一区二区 | 一级片免费播放 | 91精品国产综合久久久蜜臀九色 | 国产日韩精品一区二区 | 欧美手机在线 | 欧美一级淫片免费视频魅影视频 | 久久精品国产一区 | 精品一区二区三区三区 | 午夜激情福利 | 欧美亚洲激情 | 国产精品成人国产乱一区 | av毛片网站 | 欧美精品一区在线观看 | 色爱天堂| 日韩一区在线播放 | 羞羞在线视频 | 午夜视频在线播放 | 国产亚洲视频在线观看 | 欧美日本在线观看 | 午夜av免费 | 欧美日韩成人在线 | 中文字幕自拍偷拍 | 久久久久久av | 一级特黄视频 | www.毛片.com| 日日日干干干 | 日韩精品视频免费在线观看 | 91精品国|