php的curl选择其他网卡的ip来访问网站
php无法像python的scarpy库一样,绑定网卡。只有每次发送请求时都指定ip。
function getHtml($url)
{
ip=ip=this->ip;
ch=curlinit();
curlsetopt(ch=curlinit();
curlsetopt(ch, CURLOPT_URL, url);
curlsetopt(url);
curlsetopt(ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(ch,CURLOPTREFERER,′http://weixin.sogou.com/weixin′);
curlsetopt(ch,CURLOPTREFERER,′http://weixin.sogou.com/weixin′);
curlsetopt(ch, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt(ch,CURLOPTTIMEOUT,10);
curlsetopt(ch,CURLOPTTIMEOUT,10);
curlsetopt(ch, CURLOPT_MAXREDIRS,1);
curl_setopt(ch,CURLOPTHTTPHEADER,array("REMOTEADDR:ch,CURLOPTHTTPHEADER,
array("REMOTEADDR:ip", "HTTP_X_FORWARDED_FOR: ip"));
curlsetopt(ip"));
//这一段为指定ipcurlsetopt(ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt(ch,CURLOPTFOLLOWLOCATION,1);
curlsetopt(ch,CURLOPTFOLLOWLOCATION,1);
curlsetopt(ch, CURLOPT_HEADER, 1);
content=curlexec(content=curlexec(ch);
code=curlgetinfo(code=curlgetinfo(ch,CURLINFO_HTTP_CODE);
curl_close(ch);if(ch);if(code=='404'){
return false;
}
return $content;
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: