5 Common examples of PHP curl php code
// 1. capture the file $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL ," http://localhost/mytest/phpinfo.php "); Curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // If you comment out this line, $ result = curl_exec ($ ch); curl_close ($ ch); // 2 is output directly, and $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL ," http://blog.51yip.com "); Curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, batch, 1); curl_setopt ($ ch, CURLOPT_HTTPPROXYTUNNEL, TRUE); curl_setopt ($ ch, CURLOPT_PROXY, 125.21.23.6: 8080); // url_setopt ($ ch, CURLOPT_PROXYUSERPWD, 'User: password'); add $ result = curl_exec ($ ch) to the password ); curl_close ($ ch); // 3. after The post data, capture the data $ ch = curl_init ();/* note that, the data to be submitted cannot be a two-dimensional array or higher * for example, array ('name' => serialize (array ('tank', 'Zhang '), 'sex' => 1, 'birth' => '000000') * for example, array ('name' => array ('tank', 'zhang'), 'sex' => 1, */$ data = array ('name' => 'test', 'sex' => 1, 'birth' => '20140901'); curl_setopt ($ ch, CURLOPT_URL ,' http://localhost/mytest/curl/upload.php '); Curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); curl_exec ($ ch); // 4. capture some pages with page access control $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL ," http://club-china ");/* CURLOPT_USERPWD is mainly used to crack page access control * for example, we usually generate page control for htpasswd. * // Curl_setopt ($ ch, CURLOPT_USERPWD, '2017: 231144 XTAjmd = '); curl_setopt ($ ch, CURLOPT_HTTPGET, 1); curl_setopt ($ ch, CURLOPT_REFERER ," http://club-china "); Curl_setopt ($ ch, CURLOPT_HEADER, 0); $ result = curl_exec ($ ch); curl_close ($ ch); // 5. simulate logon to sina functionchecklogin ($ user, $ password) {if (emptyempty ($ user) | emptyempty ($ password) {return0;} $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_REFERER ," http://mail.sina.com.cn/index.html "); Curl_setopt ($ ch, CURLOPT_HEADER, true); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_USERAGENT, USERAGENT); curl_setopt ($ ch, CURLOPT_COOKIEJAR, COOKIEJAR); curl_setopt ($ ch, CURLOPT_TIMEOUT, TIMEOUT); curl_setopt ($ ch, CURLOPT_URL ," http://mail.sina.com.cn/cgi-bin/login.cgi "); Curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS," & logintype = uid & u = ". urlencode ($ user ). "& psw = ". $ password); $ contents = curl_exec ($ ch); curl_close ($ ch); if (! Preg_match ("/Location: (. *) \/cgi \/index \. php \\? Check_time = (. *) \ n/", $ contents, $ matches) {return0;} else {return1 ;}} define (" USERAGENT ", $ _ SERVER ['http _ USER_AGENT ']); define ("COOKIEJAR", tempnam ("/tmp", "cookie"); define ("TIMEOUT", 500 ); echochecklogin ("zhangying215", "xtaj227 ");