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