Http Series 1

Source: Internet
Author: User
We often use the file_get_contents function to open files. In fact, this function has another function.

We often use the file_get_contents function to open files. In fact, this function can also open a network address for simple web page capturing. when reading URLs using file-get-contents open file readfile, A $ http_response_header variable is created to save the http response header. you can use the fopen function to open the data stream information and obtain it using the stream_get_meta_data function.



$html = file_get_contents("http://baidu.com");print_r($http_response_header);/**Array([0] => HTTP/1.1 200 OK[1] => Date: Sat, 15 Nov 2014 16:14:36 GMT[2] => Server: Apache[3] => Cache-Control: max-age=86400[4] => Expires: Sun, 16 Nov 2014 16:14:36 GMT[5] => Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT[6] => ETag: "51-4b4c7d90"[7] => Accept-Ranges: bytes[8] => Content-Length: 81[9] => Connection: Close[10] => Content-Type: text/html)*/$fp = fopen("http://baidu.com", "r");print_r(stream_get_meta_data($fp));/**Array(    [wrapper_data] => Array        (            [0] => HTTP/1.1 200 OK            [1] => Date: Sat, 15 Nov 2014 16:14:36 GMT            [2] => Server: Apache            [3] => Cache-Control: max-age=86400            [4] => Expires: Sun, 16 Nov 2014 16:14:36 GMT            [5] => Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT            [6] => ETag: "51-4b4c7d90"            [7] => Accept-Ranges: bytes            [8] => Content-Length: 81            [9] => Connection: Close            [10] => Content-Type: text/html        )    [wrapper_type] => http    [stream_type] => tcp_socket/ssl    [mode] => r    [unread_bytes] => 81    [seekable] =>     [uri] => http://baidu.com    [timed_out] =>     [blocked] => 1    [eof] => )*/




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.