//隨機(jī)IP
function Rand_IP(){
$ip2id= round(rand(600000, 2550000) / 10000); //第一種方法,直接生成
$ip3id= round(rand(600000, 2550000) / 10000);
$ip4id= round(rand(600000, 2550000) / 10000);
//下面是第二種方法,在以下數(shù)據(jù)中隨機(jī)抽取
$arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
$randarr= mt_rand(0,count($arr_1)-1);
$ip1id = $arr_1[$randarr];
return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
}
//抓取頁面內(nèi)容
function Curl($url){
$ch2 = curl_init();
$user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";//模擬windows用戶正常訪問
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_TIMEOUT, 10);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
//追蹤返回302狀態(tài)碼,繼續(xù)抓取
curl_setopt($ch2, CURLOPT_HEADER, true);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch2, CURLOPT_NOBODY, false);
curl_setopt($ch2, CURLOPT_REFERER, 'http://www.baidu.com/');//模擬來路
curl_setopt($ch2, CURLOPT_USERAGENT, $user_agent);
$temp = curl_exec($ch2);
curl_close($ch2);
return $temp;
}
?php
$postData = array(
"user" => "root",
"pwd" => "123456"
);
$headerIp = array(
'CLIENT-IP:88.88.88.88',
'X-FORWARDED-FOR:88.88.88.88',
);
$refer = 'http://www.baidu.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/phpdemo/test.php');
//偽造來源refer
curl_setopt($ch, CURLOPT_REFERER, $refer);
//偽造來源ip
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerIp);
//提交post傳參
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
//...各種curl屬性參數(shù)設(shè)置
$out_put = curl_exec($ch);
curl_close($ch);
var_dump($out_put);
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》