以下是我所做的事情
下载TOR https://www.torproject.org/dist/vidalia-bundles/vidalia-bridge-bundle-0.2.4.20-0.2.21.exe
安装它
启动App
在本地主机上启动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;
它没有返回任何东西。我该怎么办?
您正在使用的example.com域名很可能不是您请求的域名。除此之外,检查apache日志。可能包含一些有趣的信息
$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);