PHP中get_headers函數使用方法解析 header是什麼意思 php header kernel headers

來源:互聯網
上載者:User
在PHP開發中,我們經常需要擷取HTTP請求中發送的伺服器資訊,本文通過一個簡單的PHP樣本介紹了通過get_headers函數擷取伺服器的相關資訊。

get_headers() 是PHP系統級函數,他返回一個包含有伺服器響應一個 HTTP 要求所發送的標題的數組。如果失敗則返回 FALSE 並發出一條 E_WARNING 層級的錯誤資訊(可用來判斷遠程檔案是否存在)。

函數定義

array get_headers ( string $url [, int $format = 0 ] )

參數

url 目標 URL

format 如果將可選的 format 參數設為 1,則 get_headers() 會解析相應的資訊並設定數組的鍵名。

樣本


以上常式的輸出類似於:

Array(    [0] => HTTP/1.1 200 OK    [1] => Date: Sat, 29 May 2004 12:28:13 GMT    [2] => Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)    [3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT    [4] => ETag: "3f80f-1b6-3e1cb03b"    [5] => Accept-Ranges: bytes    [6] => Content-Length: 438    [7] => Connection: close    [8] => Content-Type: text/html)Array(    [0] => HTTP/1.1 200 OK    [Date] => Sat, 29 May 2004 12:28:14 GMT    [Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)    [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT    [ETag] => "3f80f-1b6-3e1cb03b"    [Accept-Ranges] => bytes    [Content-Length] => 438    [Connection] => close    [Content-Type] => text/html)

以上就介紹了PHP中get_headers函數使用方法解析,包括了headers方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.