
<?php
/**
* baidu 贴吧自动回帖机
* author: hetal
* email : [email]huoqi29@163.com[/email]
* qq : 231073376
* msn : [email]hetao29@hotmail.com[/email]
* web : [url]http://www.haqoo.com[/url]
*
*/
class Baidu_Post{
var $proxyPort;
var $proxyHost;
var $cookie;
//设置代理 ,ok
function setProxy($proxyHost,$proxyPort){
$this->proxyPort=$proxyPort;
$this->proxyHost=$proxyHost;
}
//初始化baiduID ,ok
function init(){
$data = $this->_getUrl("/u/info_img/2008-08/18/logo.gif");
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $data, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=implode(';',$tmp);
}
//登录
function login($user,$pass){
$cookie=$this->cookie;
$post_data ="tpl=&tpl_ok=&skip_ok=&aid=0&need_pay=&need_coin=0&pay_method=0&u=&next_target=&return_method=&more_param=&return_type=&username=$user&password=$pass&Submit=+%B5%C7%C2%BC+";
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://passport.baidu.com/?login";
$post_port=$this->proxyPort;
$post_host=$this->proxyHost;
$connect="Proxy-Connection";
}else{
$post_url="/?login";
$post_port=80;
$connect="Connection";
$post_host="passport.baidu.com";
}
$data="POST $post_url HTTP/1.1nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*nReferer: [url]http://passport.baidu.com/?login[/url]nAccept-Language: zh-cnnContent-Type: application/x-www-form-urlencodednAccept-Encoding: gzip, deflatenUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)nHost: passport.baidu.comnContent-Length: $post_data_len$connect: Keep-AlivenCache-Control: no-cachenCookie: $cookienn$post_datan";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
fputs($sock,$data);
while($rt[]=fgets($sock)){}
fclose($sock);
$rt=implode("",$rt);
$rt=str_replace("n","",$rt);
$rt=str_replace("t","",$rt);
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=$cookie.";".implode(';',$tmp);
if(isset($tmp['BDUSS']) and !empty($tmp['BDUSS'])){
return 0;
}else{
return 1;
}
}
//得到最热的500个贴吧
function getTop500($url="http://post.baidu.com/tb/firstindex/1.html"){
/**
* baidu 贴吧自动回帖机
* author: hetal
* email : [email]huoqi29@163.com[/email]
* qq : 231073376
* msn : [email]hetao29@hotmail.com[/email]
* web : [url]http://www.haqoo.com[/url]
*
*/
class Baidu_Post{
var $proxyPort;
var $proxyHost;
var $cookie;
//设置代理 ,ok
function setProxy($proxyHost,$proxyPort){
$this->proxyPort=$proxyPort;
$this->proxyHost=$proxyHost;
}
//初始化baiduID ,ok
function init(){
$data = $this->_getUrl("/u/info_img/2008-08/18/logo.gif");
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $data, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=implode(';',$tmp);
}
//登录
function login($user,$pass){
$cookie=$this->cookie;
$post_data ="tpl=&tpl_ok=&skip_ok=&aid=0&need_pay=&need_coin=0&pay_method=0&u=&next_target=&return_method=&more_param=&return_type=&username=$user&password=$pass&Submit=+%B5%C7%C2%BC+";
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://passport.baidu.com/?login";
$post_port=$this->proxyPort;
$post_host=$this->proxyHost;
$connect="Proxy-Connection";
}else{
$post_url="/?login";
$post_port=80;
$connect="Connection";
$post_host="passport.baidu.com";
}
$data="POST $post_url HTTP/1.1nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*nReferer: [url]http://passport.baidu.com/?login[/url]nAccept-Language: zh-cnnContent-Type: application/x-www-form-urlencodednAccept-Encoding: gzip, deflatenUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)nHost: passport.baidu.comnContent-Length: $post_data_len$connect: Keep-AlivenCache-Control: no-cachenCookie: $cookienn$post_datan";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
fputs($sock,$data);
while($rt[]=fgets($sock)){}
fclose($sock);
$rt=implode("",$rt);
$rt=str_replace("n","",$rt);
$rt=str_replace("t","",$rt);
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=$cookie.";".implode(';',$tmp);
if(isset($tmp['BDUSS']) and !empty($tmp['BDUSS'])){
return 0;
}else{
return 1;
}
}
//得到最热的500个贴吧
function getTop500($url="http://post.baidu.com/tb/firstindex/1.html"){