Php 通过tor发送cURL请求?

Php 通过tor发送cURL请求?,php,curl,centos,tor,Php,Curl,Centos,Tor,我有一些向网站发送curl请求的代码,但目前只有一个网站,我不希望他们错误地禁止我的服务器IP。我是否可以通过tor网络发送这些cURL请求 我需要什么软件来完成它 运行CentOS 6.5 public function checkLogin2($email, $password, $cookiefile){ $cookiefile = 'cookies/'.$cookiefile; $handle = fopen($cookiefile, 'w+');

我有一些向网站发送curl请求的代码,但目前只有一个网站,我不希望他们错误地禁止我的服务器IP。我是否可以通过tor网络发送这些cURL请求

我需要什么软件来完成它

运行CentOS 6.5

public function checkLogin2($email, $password, $cookiefile){
        $cookiefile = 'cookies/'.$cookiefile;
        $handle = fopen($cookiefile, 'w+');
                #$proxy = 'proxy-nl.privateinternetaccess.com:1080';
                #$us = 'x9597458:Th3hXjVyuD';
        $this->_curl->setCookieFile($cookiefile);
        #$this->_curl->addOption(CURLOPT_PROXY, $proxy);
        #$this->_curl->addOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
                #$this->_curl->addOption(CURLOPT_PROXYUSERPWD, $us);
        $this->_curl->setUserAgent('FreshAndroidApp-1.3.1');
        $this->_curl->addHeader('Content-Type', 'application/x-www-form-urlencoded');
        $this->_curl->addHeader('Cookie', 'JSESSIONID=' . strtoupper(md5(time())));
        $this->_curl->addHeader('Cookie2', '$Version=1');

        try {
        $HTML = $this->_curl->post("URL HERE",
                            array('password' => $password, 
                                  'emailAddress' => $email
                            ));         

        if(!self::isJson($HTML)){
            return '{"status":"uncheck", "msg":"<font color="red"><b>Uncheck</b></font> => ' .$email.'|'.$password.'"}';

        }       
        $resp = json_decode($HTML);


        if($resp->{'status'} == "success"){
            $details = $this->_curl->get('URL HERE');
            return $details;
        } else if ($resp->{'status'} == "failure"){
            return '{"status":"failure"}';
        }
        fclose($handle);    
        } catch (CurlWrapperException $e){
            return '{"status":"socksfailure", "msg":"'.$proxy. ' => Die or timeout"}';
        }   
        fclose($handle);
    }
公共函数checkLogin2($email、$password、$cookiefile){
$cookiefile='cookies/'。$cookiefile;
$handle=fopen($cookiefile,'w+');
#$proxy='proxy nl.privateinternetaccess.com:1080';
#$us='x9597458:Th3hXjVyuD';
$this->\u curl->setCookieFile($cookiefile);
#$this->\u curl->addOption(CURLOPT\u PROXY,$PROXY);
#$this->\u curl->addOption(CURLOPT\u PROXYTYPE,CURLPROXY\u SOCKS5);
#$this->\u curl->addOption(CURLOPT\u PROXYUSERPWD,$us);
$this->_curl->setUserAgent('FreshAndroidApp-1.3.1');
$this->_curl->addHeader('Content-Type','application/x-www-form-urlencoded');
$this->_curl->addHeader('Cookie','JSESSIONID='.strtoupper(md5(time()));
$this->_curl->addHeader('Cookie2','$Version=1');
试一试{
$HTML=$this->\u curl->post(“此处的URL”,
数组('password'=>$password,
'emailAddress'=>$email
));         
如果(!self::isJson($HTML)){
返回“{”status:“uncheck”,“msg:“uncheck=>”.$email.|'.$password.“}”;
}       
$resp=json_decode($HTML);
如果($resp->{'status'}==“success”){
$details=$this->\u curl->get('URL HERE');
返回$details;
}else if($resp->{'status'}==“failure”){
返回“{”状态“:“失败”}”;
}
fclose($handle);
}捕获(CurlWrapperException$e){
返回“{”status:“socksfailure”,“msg:“.$proxy.=>Die或timeout”}”;
}   
fclose($handle);
}

您需要安装并运行TOR,如本链接所述:

然后,如果您的代码是正确的(我对PHP了解不多),只需执行以下操作:

    $this->_curl->addOption(CURLOPT_PROXY, 127.0.0.1:9050);
    $this->_curl->addOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
因为TOR代理默认在端口9050上运行。 如果您在另一台机器上运行TOR,也可以放置另一个IP而不是127.0.0.1

我认为这应该行得通