[Switch] Composer China Image Parsing file_get_contents imitating the browser header (user_agent) to get data

Source: Internet
Author: User
This article provides a detailed analysis of the data obtained by imitating the browser header (user_agent) of file_get_contents. For more information, see

What is user agent?
The Chinese name of the user agent is the user agent (UA), which is a special string header, the server can identify the operating system and version, CPU type, browser and version, browser rendering engine, browser language, and browser plug-in used by the customer.
Websites can present different websites by judging different UA, such as mobile phone access and PC Access.
When PHP uses the file_get_contents function to collect websites, it can be viewed in a browser, but it cannot obtain any content.
This is probably because the server is configured to determine whether the request is a normal browser request based on user_agent, because the default PHP file_get_contents function does not send UA.
To collect such a website, we must have PHP simulate a browser to send UA, deceiving the website to return normal content.

The implementation is as follows:

Ini_set ('user _ agent', 'mozilla/5.0 (Linux; Android 4.2.1; en-US; Nexus 4 build/jop40d) applewebkit/535.19 (khtml, like gecko) chrome/18.0.1025.166 mobile safari/535.19 ');

Here I simulate Google Chrome.

 

[Switch] Composer China Image Parsing file_get_contents imitating the browser header (user_agent) to get data

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.