PHP curl initialization and execution methods entry-level code _php instances

Source: Internet
Author: User
This is the basis of the collection, preferably familiar with

$ch = Curl_init (); # Sets the URL and returns the result, returns the header curl_setopt ($ch, Curlopt_url, ' http://www.baidu.com/'); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($this->ch, Curlopt_header, 1); # Cookie File Settings curl_setopt ($this->ch, Curlopt_cookiejar, $cookie _file); curl_setopt ($this->ch, Curlopt_cookiefile, $cookie _file); # Extra head 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, execution Expiration time curl_setopt ($this->ch, Curlopt_connecttimeout, 5); Curl_ Setopt ($this->ch, Curlopt_timeout, 30); # Whether to follow 301 302curl_setopt ($this->ch, curlopt_followlocation, 1); Curl_ Setopt ($this->ch, Curlopt_maxredirs, ten); # refercurl_setopt ($this->ch, Curlopt_referer, $refer); # HTTP version and port reuse settings curl_setopt ($this->ch, curlopt_http_version, curl_http_version_1_1); curl_setopt ($this->ch, Curlopt_forbid_reuse, 1); # support Httpscurl_setopt ($this->ch, Curlopt_ssl_verifypeer, 0); curl_setopt ($this->ch,Curlopt_ssl_verifyhost, 0); # If a millisecond timeout is required, increase: curl_setopt ($this->ch, curlopt_nosignal, 1); # Execute $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.