Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How To Anonymize PHP cURL Requests Using Tor
<?php
$ip = '127.0.0.1';
$port = '9051';
$auth = 'PASSWORD';
$command = 'signal NEWNYM';
$fp = fsockopen($ip,$port,$error_number,$err_string,10);
if(!$fp) { echo "ERROR: $error_number : $err_string";
return false;
} else {
fwrite($fp,"AUTHENTICATE \"".$auth."\"\n");
$received = fread($fp,512);
fwrite($fp,$command."\n");
$received = fread($fp,512);
}
fclose($fp);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://whatismyip.org");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$response = curl_exec($ch);
@agnelvishal

This comment has been minimized.

Copy link

commented Feb 2, 2017

End it with ?>

@agnelvishal

This comment has been minimized.

Copy link

commented Feb 24, 2017

Tor proxy is set but the command signal NEWNYM does not seem to work as ip does not change everytime

@rkrx

This comment has been minimized.

Copy link

commented Dec 21, 2017

@atefBB

This comment has been minimized.

Copy link

commented Aug 8, 2018

@zachflower You should close the cURL session at the end of the script.
See forked gist https://gist.github.com/atefBB/4ce676818d9e178d4a855d07516736f2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.