M
M
Mile43111122020-02-20 12:04:01
proxy
Mile4311112, 2020-02-20 12:04:01

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 );
    }
}


this is how i send the request
$proxy = new Proxy();
        $curlData = $proxy->curl($page);
        $html = HtmlDomParser::str_get_html($curlData);
        $find = $this->is_find($html, ".leftcol > .area > .listItem");


after which I do a check and find out if the page data has arrived, if the data has not arrived, then it changes the IP and resends CURL

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);
        }


The IP change goes through, but for some reason the content does not arrive, there are suggestions that when changingProxyIdentity() is called, the curl_setopt( $this -> ch, CURLOPT_PROXY, $torSocks5Proxy ) option is not updated because it is in the constructor

How can this be fixed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question