Two basic phpCURL instances

Source: Internet
Author: User
: This article mainly introduces two basic phpCURL instances. For more information about PHP tutorials, see. To start preparation, first find extension = php_curl.dll in the php. ini file, remove ";", and enable curl support.

Curl_init (); // initialize curl
Curl_close (); // link curl
Curl_exec (); // perform the curl operation
Curl_setopt (int ch, string option, value) // sets the curl option
Option is the desired attribute, and value is the corresponding value.

The basic attributes of option are as follows:
CURLOPT_URL // you can specify the URL to capture a webpage.
CURLOPT_POST // use php for the httppost operation and set the option to a non-zero value
CURLOPT_POSTIELDS // all data of the post operation of the httppost operation
CURLOPT_PETURNTRANSFER // whether to return the content obtained on the page. if the value is not zero

I. Basic example

$ Curl = curl_init (); // initialize the curl object $ curl_setopt ($ curl, CURLOPT_URL, 'www .baidu.com '); // you can specify the URL of the captured page $ curl_setopt ($ curl, CURLOPT_HEADER, 1); // include a header in the output and set the value to non-zero $ response = curl_exec ($ curl); // execute the operation, run curlcurl_close ($ curl); // close the operation.

II. post data

$ Data = array ('name' => 'trany', 'age' => '12'); $ curl = curl_init (); // initialize the curl object $ curl_setopt ($ curl, CURLOPT_URL, 'www. BAIDU. COM '); // set the page capture address $ curl_setopt ($ curl, CURLOPT_POST, 1); // do httppost to submit $ curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); // pass the value $ response = curl_exec ($ curl); // execute the curl_close ($ curl) operation; // close the operation

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.