How PHP uses File_get_content to set header information _php tips

Source: Internet
Author: User
Tags exception handling php error

This example describes how PHP uses File_get_content to set header information. Share to everyone for your reference, specific as follows:

Directly on the code:

<?php/** Accept Application/json accept-encoding gzip, deflate Accept-language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Connection keep-alive Cookie Mzys_is_frist_access=1; MZYS_C_UUID=GUEST_215CBC0979B5BD2; Mzys_access20130610=1; MZYS_QZ_UUID=D6D4640F93CB7A4; Cnzzdata30040410=cnzz_eid%3d1008690174-1370849811-http%253a%252f%252fm.120ask.com%26ntime%3d1370855345%26cnzz_ a%3d43%26retime%3d1370855484258%26sin%3d%26ltime%3d1370855484258%26rtime%3d0; Phpsessid=4kacoqfe4ae33km3h0l2imjfd6 Host m.120ask.com Referer 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.0 X-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%3d1008690174-1370849811-http%253a%252f%252fm.120ask.com%26ntime%3d1370855345%26cnzz_ a%3d43%26retime%3d1370855484258%26sin%3d%26ltime%3d1370855484258%26rtime%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);
Mode 1//$fp = fopen ("http://m.120ask.com/health/show?page=2&id=84882&type=17", ' R ', false, $context);
Fpassthru ($FP);
Fclose ($FP);

 Mode 2//echo file_get_contents (' http://m.120ask.com/health/show?page=2&id=84882&type=17 ', 0, $context);

More interested in PHP related content readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP error and Exception handling method summary" and "PHP common functions and Skills summary"

I hope this article will help you with the PHP program design.

Related Article

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.