TheXReflex TheXReflex - 4 months ago 38
PHP Question

PHP cURL over TOR what am I doing wrong?

So I'm trying to cURL to an onion site, e.g: facebookcorewwwi.onion
I would have the following code:

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl, CURLOPT_URL, 'http://facebookcorewwwi.onion/');
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:9050');
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
$html = curl_exec($curl);
var_dump($html);


This gives the following output:

bool(false)


yet this is not what I want as a result, I want the actual page content!

inb4: yes I have the tor browser open

curl_error gives the following error:

Error: Failed to connect to 127.0.0.1 port 9050: Connection refused

Answer

From the php docs for curl_exec:

Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.

If curl_exec is returning a boolean of false, an error has occurred. Try fetching the error:

$html = curl_exec($curl);
if ( $html === false ) {
   echo 'Error: ' . curl_error($curl);
}
Comments