PHPcURL initialization and execution method entry-level code

Source: Internet
Author: User
This article mainly introduces the entry-level code of PHPcURL initialization and execution method. This article provides a sample code that contains detailed comments. if you need it, you can refer to it as a collection basis.

$ Ch = curl_init (); # set the url and return the result. whether to return the header curl_setopt ($ ch, CURLOPT_URL ,' http://www.baidu.com/ '); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ this-> ch, CURLOPT_HEADER, 1); # curl_setopt ($ this-> ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_setopt ($ this-> ch, CURLOPT_COOKIEFILE, $ cookie_file); # extra header curl_setopt ($ this-> ch, CURLOPT_HTTPHEADER, array ('User-Agent: mozilla/5.0 '); # set postcurl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ poststring ); # connection and execution expiration time curl_setopt ($ this-> ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt ($ this-> ch, CURLOPT_TIMEOUT, 30 ); # follow 301 302curl_setopt ($ this-> ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ this-> ch, CURLOPT_MAXREDIRS, 10); # refercurl_setopt ($ this-> ch, CURLOPT_REFERER, $ refer); # set curl_setopt for http version and Port reuse ($ this-> ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt ($ this-> ch, forward, 1 ); # support httpscurl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ this-> ch, CURLOPT_SSL_VERIFYHOST, 0); # if millisecond timeout is required, add: curl_setopt ($ this-> ch, CURLOPT_NOSIGNAL, 1); # run $ response = curl_exec ($ ch); if (curl_errno ($ ch) {curl_error ($ ch ); exit ();} curl_close ($ ch );

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.