茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    PHP中header函數(shù)的用法及其注意事項詳解
    來源:易賢網(wǎng) 閱讀:1175 次 日期:2016-08-17 15:33:37
    溫馨提示:易賢網(wǎng)小編為您整理了“PHP中header函數(shù)的用法及其注意事項詳解”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了PHP中header函數(shù)的用法及其注意事項 的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下

    void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) : Send a raw HTTP header

    下面有一些使用header的幾種用法:

    1、使用header函數(shù)進行跳轉(zhuǎn)頁面;

    header('Location:'.$url);

    其中$url就是將要跳轉(zhuǎn)的url了。

    這種用法的注意事項有以下幾點:

    •Location和":"之間不能有空格,否則會出現(xiàn)錯誤(注釋:我剛測試了,在我本地環(huán)境下,沒有跳轉(zhuǎn)頁面,但是也沒有報錯,不清楚什么原因); 

    •在用header前不能有任何的輸出(注釋:這點大家都知道的,如果header之前有任何的輸出,包括空白,就會出現(xiàn)header already sent by xxx的錯誤);

    •header 后面的東西還會執(zhí)行的;

    2、使用header聲明content-type

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

    這個沒有什么好說的;

    3、使用header返回response 狀態(tài)碼

    header(sprintf('%s %d %s', $http_version, $status_code, $description));

    樣式就是這樣的;

    例如:header('HTTP/1.1 404 Not Found');

    4、使用header在某個時間后執(zhí)行跳轉(zhuǎn)

    header("Refresh: {$delay}; url={$url}");

    其中$delay就是推遲跳轉(zhuǎn)的時間,$url為需要跳轉(zhuǎn)的url

    例如:header('Refresh: 10; url=http://www.example.org/'); 意思為10s后跳轉(zhuǎn)到http://www.eexample.org這個網(wǎng)站

    5、使用header控制瀏覽器緩存

    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、使用header進行下載操作

    header('Content-Type: application/octet-stream');//設(shè)置內(nèi)容類型

    header('Content-Disposition: attachment; filename="example.zip"'); //設(shè)置MIME用戶作為附件下載 如果將attachment換成inline意思為在線打開

    header('Content-Transfer-Encoding: binary');//設(shè)置傳輸方式

    header('Content-Length: '.filesize('example.zip'));//設(shè)置內(nèi)容長度

    // load the file to send:

    readfile('example.zip');//讀取需要下載的文件

    下面再給大家介紹PHP header 的幾種用法

    跳轉(zhuǎn)頁面

    header('Location:'.$url); //Location和":"之間無空格。

    聲明content-type

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

    返回response狀態(tài)碼

    header('HTTP/1.1 404 Not Found');

    在某個時間后執(zhí)行跳轉(zhuǎn)

    header('Refresh: 10; url=http://www.baidu.com/'); //10s后跳轉(zhuǎn)。

    控制瀏覽器緩存

    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");

    執(zhí)行http驗證

    header('HTTP/1.1 401 Unauthorized');

    header('WWW-Authenticate: Basic realm="Top Secret"');

    執(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)容長度

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:PHP中header函數(shù)的用法及其注意事項詳解

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)