Answer the question
In order to leave comments, you need to log in
How will the curl_setopt( $this -> ch, CURLOPT_PROXY, $torSocks5Proxy ) option be updated when changingProxyIdentity() is called?
Here is the Proxy class itself with changeProxyIdentity() methods , and sending curl
class Proxy {
private $ch, $proxy;
function __construct() {
$torSocks5Proxy = "socks5://127.0.0.1:9050";
// $torSocks5Proxy = "127.0.0.1:9050";
$this -> ch = curl_init();
curl_setopt( $this -> ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5 );
curl_setopt( $this -> ch, CURLOPT_PROXY, $torSocks5Proxy );
curl_setopt( $this -> ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $this -> ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $this -> ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $this -> ch, CURLOPT_HEADER, false );
}
public function curl( $url, $postParameter = null ) {
if ( is_array($postParameter) && count( $postParameter ) > 0 )
curl_setopt( $this -> ch, CURLOPT_POSTFIELDS, $postParameter );
curl_setopt( $this -> ch, CURLOPT_URL, $url );
return curl_exec( $this -> ch );
}
public function changeProxyIdentity() {
$ip = '127.0.0.1';
$port = '9051';
$fp = fsockopen( $ip, $port, $error_number, $err_string, 10 );
if ( !$fp ) {
echo "Error while changing Tor proxy identity: {$error_number} : {$err_string}";
return false;
} else {
fwrite( $fp, "AUTHENTICATE\n" );
$received = fread( $fp, 512 );
fwrite( $fp, "signal NEWNYM\n" );
$received = fread( $fp, 512 );
}
sleep(1);
fclose( $fp );
return $received;
}
function __destruct() {
curl_close( $this -> ch );
}
}
$proxy = new Proxy();
$curlData = $proxy->curl($page);
$html = HtmlDomParser::str_get_html($curlData);
$find = $this->is_find($html, ".leftcol > .area > .listItem");
if ($find == 0) {
$proxy = new Proxy();
$proxy->changeProxyIdentity();
$this->new_ip = $this->getIp();
$curlData = $proxy->curl($page);
$html = HtmlDomParser::str_get_html($curlData);
$find = $this->is_find($html, ".leftcol > .area > .listItem");
echo 'new: '.$this->new_ip . '| old: '. $this->old_ip;
dd($find);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question