Php_curl.dll Extension Introduction and explanation
, what is curl and what functions can be achieved?
What is Curl
Curl is a file transfer tool that works with URL syntax in the 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 continuation and so on, the function is very powerful.
These features are commonly implemented in PHP:
1. Realize remote acquisition and acquisition of content
2, the implementation of PHP Web version of the FTP upload download
3. Realize the simulation landing
4. Interface docking (API), data transmission, etc.
5. Realization of analog cookies, etc.
1 The first step in the entire operation is to initialize the
$curl = Curl_init (') with the Cur_init () function. Www.php100.com ');
2 Then set the option with the curl_setopt () function. After the
3 is set, execute the transaction curl_exec ($curl);
4 finally close curl_close ();
3, using PHP curl for transport and get 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);
//sets the curl parameter, which requires the result to be saved to a string or output to the screen.
$data = curl_exec ($curl);//Run Curl, request 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 Simulation login process and Steps
2, Tempnam create a temporary file
3, use curl simulation to login to PHP100 forum
!--? php
$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 ("/
????? (. *) <\/li>/", $contents, $arr);
echo $arr [1];
Curl_close ($ch);
?>