In PHP development, we often need to get the server information sent in the HTTP request, this article through a simple PHP example of the Get_headers function to obtain information about the server.
Get_headers () is a PHP system-level function that returns an array containing the headers sent by the server in response to an HTTP request. If it fails, it returns false and emits an e_warning level error message (which can be used to determine if the remote file exists).
function definition
Array get_headers (string $url [, int $format = 0])
Parameters
URL Destination URL
Format if the optional format parameter is set to 1, Get_headers () parses the corresponding information and sets the array's key name.
Example
The output of the above routines is similar to the following:
Array ( [0] = http/1.1 [ 1] = Date:sat, May 2004 12:28:13 GMT [2] = server:apache/1.3.27 (Unix) (Red-hat/linux) [3] = last-modified:wed, Jan 2003 23:11:55 GMT [4] = ETag: "3f80f-1b6-3e1cb03b" [5] = = Accept-range S:bytes [6] = content-length:438 [7] = Connection:close [8] = content-type:text/html) Array ( C10/>[0] = http/1.1 [Date] + Sat, May 2004 12:28:14 GMT [Server] + apache/1.3.27 (Unix)
(Red-hat/linux) [last-modified] = Wed, Jan 2003 23:11:55 GMT [ETag] = "3f80f-1b6-3e1cb03b" [accept-ranges] = bytes [Content-length] = 438 [Connection] = Close [Content-type] = text/html)
The above introduces the use of get_headers function in PHP parsing, including the headers aspects of the content, I hope that the PHP tutorial interested in a friend helpful.