让HTTP代理更加智能化

一、HTTP代理的应用环境

刷票、发帖、刷流量等需要在短时间内换大量IP的应用

二、在使用HTTP代理的难点

1.选出能有且速度快的代理较难

2.用选出的代理在实际使用中会出现不稳定情况,需要针对此IP进行智能化的再鉴定和剔除工作

3.伪造初始IP地址,如果只是简单的应用代理,服务器很简单的就能检测出原始IP

三、程序的书写

[php]
public function get($url) {
$this->curl = curl_init();
if($this->proxy){
curl_setopt ($this->curl, CURLOPT_PROXY,$this->proxy);
curl_setopt ($this->curl, CURLOPT_HTTPHEADER, array(‘CLIENT-IP:’.$this->client_ip, ‘X-FORWARDED-FOR:’.$this->client_ip));
echo $this->proxy;
}
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_HEADER, 1);
curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($this->curl, CURLOPT_COOKIE, $this->cookie);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($this->curl);
curl_close($this->curl);
preg_match_all("/Set-Cookie:(.*?);/", $data, $match, PREG_SET_ORDER);
foreach ($match as $r) {
if ($this->cookie != ”) {
$this->cookie = $this->cookie . ‘;’;
}
if (isset($r[1])) {
$this->cookie .= trim(str_replace("rn", "", $r[1]));
}
}
$this->set($this->cookie_name,$this->cookie);
return $data;

}
[/php]

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据