A detailed introduction to the function and usage of get_headers functions in PHP _php example

Source: Internet
Author: User

Get_headers () is a PHP system-level function that returns an array containing the headers that the server responds to an HTTP request. Returns False if it fails and emits a e_warning-level error message that can be used to determine whether a remote file exists.

function definition

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

Parameters

URL Destination URL

Format if you set the optional format parameter to 1, Get_headers () parses the appropriate information and sets the key name of the array.

Example

<?php
$url = ' http://www.phpernote.com ';
Print_r (Get_headers ($url));
Print_r (Get_headers ($url, 1));
?>

The output of the above routine is similar to the following:

Array
(
    [0] => http/1.1 OK
    [1] => Date: Sat, May 12:28:13 GMT
    [2] => server:apache/1.3.27 (Unix)   (red-hat/linux)
  ;   [3] => last-modified:wed, 2003 23:11:55 GMT
    [4] => ETag: "3f80f-1b6-3e1c b03b "
    [5] => accept-ranges:bytes
    [6] => content-length:438
    [7] => connection:close
    [8] => content-type:text/html

Array
(
[0] => http/1.1 OK
[Date] => Sat, May 12:28:14 GMT
[Server] => apache/1.3.27 (Unix) (Red-hat/linux)
[Last-modified] => Wed, 2003 23:11:55 GMT
[ETag] => "3f80f-1b6-3e1cb03b"
[Accept-ranges] => bytes
[Content-length] => 438
[Connection] => Close
[Content-type] => text/html
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.