PHP uses file_get_content to set header information

Source: Internet
Author: User
This article describes how to use file_get_content to set the header information in PHP, and compares and analyzes the related techniques of using fopen and file_get_contents to set and obtain the header information in PHP based on examples, for more information about how to use file_get_content to set header information in PHP, see the following example. We will share this with you for your reference. The details are as follows:

Directly run the code:

<? Php/** Accept application/jsonAccept-Encoding gzip, deflateAccept-Language zh-cn, zh; q = 0.8, en-us; q = 0.5, en; q = 0.3 Connection keep-aliveCookie mzys_is_frist_access = 1; mzys_c_uuid = nobody; mzys_access20130610 = 1; mzys_qz_uuid = d6d4640f93cb7a4; CNZZDATA30040410 = cnzz_eid % hour % 253A % 252F % hour % 26 ntime % 3D1370855345% 26cnzz_a % 3D43% 26 retime % hour % 26sin % 3D % 26 ltime % hour % 26 rtime % 3D0; PHPSESSID = 4kacoqfe4ae33km3h0l2imjfd6Host m.120ask. comReferer http://m.120ask.com/health/show?page=2&id=84882&type=17 User-Agent Mozilla/5.0 (Windows NT 6.1; rv: 21.0) gecko/20100101 Firefox/21.0X-Requested-With XMLHttpRequest */$ hdrs = array ('http' => array ('header' => "Accept: application/json \ r \ n ". "Accept-Encoding: gzip, deflate \ r \ n ". "Accept-Language: zh-cn, zh; q = 0.8, en-us; q = 0.5, en; q = 0.3 \ r \ n ". "Accept-Encoding: gzip, deflate \ r \ n ". "Connection: keep-alive \ r \ n ". "Cookie: mzys_is_frist_access = 1; mzys_c_uuid = guest_215cbc0979b5bd2; mzys_access20130610 = 1; mzys_qz_uuid = d6d4640f93cb7a4; CNZZDATA30040410 = cnzz_eid % hour % 253A % 252F % hour % 26 ntime % 3D1370855345% 26cnzz_a % 3D43% 26 retime % hour % 26sin % 3D % 26 ltime % hour % 26 rtime % 3D0; PHPSESSID = 4kacoqfe4ae33km3h0l2imjfd6 \ r \ n ". "Host: m.120ask.com \ r \ n ". "Referer: http://m.120ask.com/health/show?page=2&id=84882&type=17 \ R \ n ". "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv: 21.0) Gecko/20100101 Firefox/21.0 \ r \ n ". "X-Requested-With: XMLHttpRequest", 'timeout' => 2),); $ context = stream_context_create ($ hdrs ); // method 1 // $ fp = fopen (" http://m.120ask.com/health/show?page=2&id=84882&type=17 ", 'R', false, $ context); // fpassthru ($ fp); // fclose ($ fp); // method 2 // echo file_get_contents (' http://m.120ask.com/health/show?page=2&id=84882&type=17 ', 0, $ context );

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.