PHP: simple CURL application instance

Source: Internet
Author: User
As a PHP developer or a person who frequently accesses the PHP source code, CURL is very familiar with it. But do you really know CURL? Don't you just know what it is for, or you just know it. In fact, the CURL component is often seen and widely used in many places. For example, capture a page and submit it to the page

As a PHP developer or a person who frequently accesses the PHP source code, CURL is very familiar with it. But do you really know CURL? Don't you just know what it is for, or you just know it. In fact, the CURL component is often seen and widely used in many places. For example, capture a page and submit it to the page

As a PHP developer or a person who frequently accesses the PHP source code, CURL is very familiar with it. But do you really know CURL? Don't you just know what it is for, or you just know it. In fact, the CURL component is often seen and widely used in many places. For example, capture a page and submit data to the page. It can be said that CURL is the same as other popular applications and must be mastered. Next, let's look at an instance that uses CURL to capture pages:

Function curl_download ($ Url) {// to prevent errors, check whether the CURL component if (! Function_exists ('curl _ init ') {die (Sorry, the curl component is not installed! ');} // Yes. Now that we have installed a new handle $ ch = curl_init (); // you can set the curl_setopt ($ ch, CURLOPT_URL, $ Url) address to be crawled ); // create an http Referer. Some websites will determine the request route. We can forge curl_setopt ($ ch, CURLOPT_REFERER, "Callback); // set the user proxy curl_setopt ($ ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // do you want to include the header ID (0 = yes, 1 = no) curl_setopt ($ ch, CURLOPT_HEADER, 0 ); // determine whether to return or print the data (true = return, false = print) curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); // The number of timeout seconds curl_setopt ($ ch, CURLOPT_TIMEOUT, 10); // start capturing and return the corresponding data $ output = curl_exec ($ ch); // close the connection curl_close ($ ch); return $ output ;}

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.