Home > Backend Development > PHP Tutorial > PHP uses file_get_content to set header information, phpgetfilecontent_PHP tutorial

PHP uses file_get_content to set header information, phpgetfilecontent_PHP tutorial

WBOY
Release: 2016-07-12 08:59:21
Original
1137 people have browsed it

PHP uses file_get_content to set header information, phpgetfilecontent

This article describes the example of PHP using file_get_content to set header information. Share it with everyone for your reference, the details are as follows:

Go directly to the code:

<&#63;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&#63;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&#63;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);
//方式1
// $fp = fopen("http://m.120ask.com/health/show&#63;page=2&id=84882&type=17", 'r', false, $context);
// fpassthru($fp);
// fclose($fp);
//方式2
//echo file_get_contents('http://m.120ask.com/health/show&#63;page=2&id=84882&type=17', 0, $context);

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction Tutorial on PHP Basic Syntax", "Summary of PHP Error and Exception Handling Methods" and "Summary of Common PHP Functions and Techniques"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Solution to the error of grabbing https address by file_get_contents function in PHP (two methods)
  • PHP file_get_contents function times out when reading remote data Solution
  • Using file_get_contents in PHP Post data code example
  • Using file_get_contents in PHP to crawl Chinese garbled web pages Solution to the problem
  • php Method of using file_get_contents to read large files
  • Comparative analysis of the performance of file_get_contents and curl in PHP
  • Examples of advanced usage of file_get_contents in PHP
  • Comparison of the usage of the three functions curl, fsocket and file_get_content in PHP
  • PHP file_get_contents setting timeout processing method
  • Usage example of PHP stream_context_create() function
  • Analysis of the role and usage of PHP stream_context_create()
  • Breaking through the anti-hotlinking measures based on HTTP_REFERER in PHP (stream_context_create)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1099059.htmlTechArticlePHP uses file_get_content to set header information, phpgetfilecontent This example describes how PHP uses file_get_content to set header information. Share it with everyone for your reference, specifically...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template