Php uses curl to capture content from random IP addresses.

Source: Internet
Author: User

Php uses curl to capture content from random IP addresses.

This example describes how php captures content from random IP addresses based on curl. We will share this with you for your reference. The details are as follows:

Using php curl, we can simulate user behavior. We can set the ip address and browser information we access, and set the post method.

Curl is an amazing thing !~ You can generate random ip addresses for access, or even make the server unable to identify the real ip address. This is awesome! Some people say this is not a bug. However, this feature also brings us great convenience.

Php implements random ip Access Based on curl:

<? Phpfunction curl ($ url, $ ifpost = 0, $ datafields = '', $ cookiefile ='', $ v = false) {$ ip_long = array ('20140901 ', '20140901'), // 36.56.0.0-36.63.255.255 array ('20160301', '20160301'), // 61.232.0.0-61.237.255.255 array ('20160301', '20160301 '), // 106.80.0.0-106.95.20.255 array ('20160301', '20160301'), // 121.76.0.0-121.77.0000255 array ('20160301', '20160301'), // 123.232.0.0-12 3.235.0000255 array ('-100','-100'), // 139.196.0.0-139.215.0000255 array ('-100','-100 '), // 171.8.0.0-171.15.255.255 array ('-100','-100'), // 182.80.0.0-182.92.20.255 array ('-100','-100 '), // 210.25.0.0-210.47.0000255 array ('-000000','-000000'), // 222.16.0.0-222.95.0000255); $ rand_key = mt_rand (0, 9 ); $ ip = long2ip (mt_rand ($ ip_long [$ ran D_key] [0], $ ip_long [$ rand_key] [1]); $ header = array ("Connection: Keep-Alive", "Accept: text/html, application/xhtml + xml, */* "," Pragma: no-cache "," Accept-Language: zh-Hans-CN, zh-Hans; q = 0.8, en-US; q = 0.5, en; q = 0.3 "," User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) ", 'client-IP :'. $ ip, 'x-FORWARDED-:'. $ ip); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl _ Setopt ($ ch, CURLOPT_HEADER, $ v); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); $ ifpost & curl_setopt ($ ch, CURLOPT_POST, $ ifpost ); $ ifpost & curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ datafields); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true ); $ cookiefile & curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookiefile); $ cookiefile & curl_setopt ($ ch, CURLOPT_COOK IEJAR, $ cookiefile); curl_setopt ($ ch, CURLOPT_TIMEOUT, 30); // maximum number of seconds allowed for execution $ OK = curl_exec ($ ch); curl_close ($ ch ); unset ($ ch); return $ OK;} print_r (curl ("URL");?>

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.