Programming-questions about how PHP, such as curl and file_get_contents, can obtain webpage content Functions

Source: Internet
Author: User
If the URL is directly input in the browser, the content is correctly displayed, but an empty string is returned when the content is obtained by a function or component such as CURL or filegetcontents. This problem occurs when I used PHP to capture Baidu dictionary content. This also happens when I capture 12306 of data a few days ago. Please... if the URL is directly entered in the browser, the content is correctly displayed, but the CURL or file GetWhen a function or component such as contents obtains the content, an empty string is returned. This problem occurs when I used PHP to capture the content of Baidu dictionary. This also happened when I captured 12306 of the data a few days ago. How did they identify it? Is there any solution? Thank you!

Reply content:

If the URL is directly entered in the browser, the content is correctly displayed, but the CURL or fileGetWhen a function or component such as contents obtains the content, an empty string is returned. This problem occurs when I used PHP to capture the content of Baidu dictionary. This also happened when I captured 12306 of the data a few days ago. How did they identify it? Is there any solution? Thank you!

1. Set user_agent to the browser. 2. Set referrer correctly. 3. Add cookie4. other additional items.

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.