Home > Backend Development > PHP Tutorial > Introduction and detailed explanation of php_curl.dll extension_PHP tutorial

Introduction and detailed explanation of php_curl.dll extension_PHP tutorial

WBOY
Release: 2016-07-15 13:21:54
Original
1125 people have browsed it

, What is CURL and what functions can it achieve?​

What is CURL
curl is a file transfer tool that uses URL syntax to work in command line mode. It supports many protocols: FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP. Curl also supports HTTPS authentication, HTTP POST method, HTTP PUT method, FTP upload, HTTP upload, proxy server, cookies, username/password authentication, download file breakpoint resuming, etc. It is very powerful.
Those functions commonly used in PHP are:
1. Realize remote acquisition and collection of content
2. Implement FTP upload and download of PHP web version
3. Implement simulated login
4. Implement interface docking (API), data transmission, etc.
5. Implement simulated cookies, etc.
2. How to use CURL function in PHP
1 The first step in the entire operation process is to initialize with the cur_init() function
$curl = curl_init(‘www.php100.com’);
2 Then, use the curl_setopt() function to set the options.
3 After setting, execute the transaction curl_exec($curl);
4 Finally close curl_close();
3. Use PHP CURL to implement transmission and acquisition functions
$curl = curl_init(); //Initialize a cURL object
curl_setopt($curl, CURLOPT_URL, "http://www.php100.com");
//Set the URL you need to crawl
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//Set cURL parameters and require the results to be saved in a string or output to the screen.
$data = curl_exec($curl); //Run cURL and request the web page
curl_close($curl); //Close URL request
===========
$user = "admin";
$pass = "admin100";
$curlPost = "user=$user&pass=$pass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/edu/login.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);
curl_close($ch);
1. CURL simulated login process and steps
2. tempnam creates a temporary file
3. Use CURL to simulate logging in to the bkJia forum
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.php100.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=php100-88&pwpwd=111111';
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$url='http://bbs.php100.com/userpay.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/
  • ?????(.*)
  • /",$contents,$arr);
    echo $arr[1];
    curl_close($ch);
    ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477131.htmlTechArticle, What is CURL and what functions can it achieve? What is CURL curl is a file transfer tool that uses URL syntax to work in command line mode. It supports many protocols: FTP, FTPS, HTTP, HTT...
    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