Get a Web page with a Curl session

Source: Internet
Author: User

1, Curl_init
Role:
Initializes a new session, returning a curl handle for use by the curl_setopt (), curl_exec (), and curl_close () functions.
Format: Curl_init ([string $url = NULL])
If a parameter $url is provided, the CURLOPT_URL option will be set to this value. or use the curl_setopt () function to set this value manually.
function execution returns a curl handle if successful, error returns FALSE.

2, curl_setopt
Function: Set an option for a given Curl session handle
Format: curl_setopt (resource $ch, int $option, mixed $value)
Where parameters: Ch is returned by Curl_init () to the curl handle.
Option needs to set the CURLOPT_XXX options.
Value will be set on the option options.
Returns TRUE when the function executes successfully, FALSE on failure

3, Curl_exec
Function: Executes a given curl session. This function should be called after initializing a curl session and all of the options are set.
Format: curl_exec (Resource $ch)
Where the parameter $ch is the curl handle returned by Curl_init ().
Returns TRUE when the function executes successfully, or FALSE on failure. However, if the Curlopt_returntransfer option is set, the execution result is returned when the function executes successfully, and FALSE on failure.

4, Curl_close
Function: Closes a curl session and frees all resources. The curl handle CH will also be released.
Format: Curl_close (Resource $ch)
Where the parameter $ch is the curl handle returned by Curl_init ().
The function is of type void and has no return value.

Example: Initializing a new curl session and getting a Web page

<?php//Create a new curl resource $ch = Curl_init ();//Set URL and corresponding options curl_setopt ($ch, Curlopt_url, "http://blog.csdn.net/liuruiqun/ curl_setopt ($ch, Curlopt_header, 0);//crawl the URL and pass it to the browser curl_exec ($ch);//Close the Curl resource and release the system Resource Curl_close ($CH); >


Get a Web page with a Curl session

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.