Detailed explanation of basic operations of php curl_PHP tutorial

WBOY
Release: 2016-07-21 14:59:50
Original
1438 people have browsed it

cURL is a tool for connecting and communicating with various servers using various types of protocols. It is a powerful library that supports http, https, ftp, telnet, file and other protocols. It also supports HTTPS authentication, HTTP POST, HTTP PUT, FTP upload, HTTP form-based upload, proxy, cookies and username + password authentication. .

Maybe you have also used the file_get_contents() function, but this method is insufficient for handling cookies, verification, form submission, file upload, etc.

The basic method of using cURL is as follows:
First modify the settings of the php.ini file, find php_curl.dll, and uncomment extension=php_curl.dll, because php defaults to cURL is not enabled.

Then there are the basic steps:
1. Initialization
2. Set variables (curl_setopt)
3. Execute and get the results (curl_exec )
4. The output
php example is as follows:

Copy code The code is as follows:

// Initialization
$ch = curl_init();
// Set options, including URL
curl_setopt($ch, CURLOPT_URL,"http://www.baidu .com");
//Whether to return parameters to the page (0 means yes, 1 means no)
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER,0) ;
//Execute and get the HTML document content
$output = curl_exec($ch);
//Close url
curl_close($ch);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328106.htmlTechArticlecURL is a tool for connecting and communicating with various servers using various types of protocols. It is a powerful library that supports http, https, ftp, telnet, file and other protocols, and also supports HTTP...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template