当我使用TOR时,CURL不会返回任何内容。我该怎么办?

时间:2014-03-14 08:47:55

标签: php curl tor

以下是我做的事情

已下载TOR https://www.torproject.org/dist/vidalia-bundles/vidalia-bridge-bundle-0.2.4.20-0.2.21.exe

已安装

启动了应用

在localhost上启动WAMP使用此代码进行连接。

/URL
$url = "http://whatismyip.org";

//Headers
$headers = array(
  'Host: www.example.com',
  'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'Referer: http://www.example.com/index.php'
);

//Tor address & port
$tor = '127.0.0.1:9050';

//cURL
$ch = curl_init();

//Set proxy
curl_setopt($ch, CURLOPT_PROXY, $tor);

//Set proxy type
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

//The URL to which to POST the data
curl_setopt($ch, CURLOPT_URL, $url);

//Set request headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

//Prepare for the POST operation
curl_setopt($ch, CURLOPT_POST, 1);


//Follow any "Location: " header that the server sends
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

//Don't return HTTP headers
curl_setopt($ch, CURLOPT_HEADER, 0);

//Return the contentof the call
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Execute
$result = curl_exec($ch);

echo $result;

它没有返回任何东西。我该怎么办?

2 个答案:

答案 0 :(得分:0)

您正在使用的example.com域名很可能不是您要求的域名。除此之外,请检查apache日志。可能包含一些有关的信息。

答案 1 :(得分:0)

    $proxy = "127.0.0.1";
    $port = "9050";
    $url = "http://whatismyip.org";
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_PROXYTYPE, 7 );
    curl_setopt ($ch, CURLOPT_PROXY, $proxy.':'.$port );
    ob_start();

    curl_exec ($ch);
    curl_close ($ch);

    $result = ob_get_contents();
    ob_end_clean();
    var_dump($result);