5 Common examples of PHP curl-PHP source code

Source: Internet
Author: User
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 ");

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.