Question

I have a Pagerank checking script that i'd like to add proxies to. I usually use Curl so im not sure exactly how to go about making the request through a proxy. I want the request to pick a random proxy from the $proxies array and use that for the request. Can anyone walk me through how this is done using this script. Thanks in advance.

$proxyauth = "username:password";

$proxies = array(
    "proxy1",
    "proxy2",
    "proxy3",
    "proxy4",
    "proxy5",
    "proxy6",
    "proxy7",
    "proxy8",
    "proxy9",
    "proxy10"
);

function check($page){
    // Open a socket to the toolbarqueries address, used by Google Toolbar
    $socket = fsockopen("toolbarqueries.google.com", 80, $errno, $errstr, 30);

    // If a connection can be established
    if($socket) {
        // Prep socket headers
        $out = "GET /tbr?client=navclient-auto&ch=".$this->checkHash($this->createHash($page))
                ."&features=Rank&q=info:".$page."&num=100&filter=0 HTTP/1.1\r\n";
        $out .= "Host: toolbarqueries.google.com\r\n";
        $out .= "User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP         5.1)\r\n";
        $out .= "Connection: Close\r\n\r\n";

        // Write settings to the socket
        fwrite($socket, $out);

        // When a response is received...
        $result = "";
        while(!feof($socket)) {
            $data = fgets($socket, 128);
            $pos = strpos($data, "Rank_");
            if($pos !== false){
                $pagerank = substr($data, $pos + 9);
                $result += $pagerank;
            }
        }
        // Close the connection
        fclose($socket);

        // Return the rank!
        return $result;
    }
}

No correct solution

OTHER TIPS

With fsockopen, instead of toolbarqueries.google.com you connect to the selected proxy. Then you send a complete URL with the GET request:

$socket = fsockopen("proxy5", 80, $errno, $errstr, 30);
...
$out = "GET http://toolbarqueries.google.com/tbr?client=..."

You can still send the Host header, but you don't need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top