PHP function to anonymize HTTP GET requests using the Tor network

<![CDATA[

Recovered from my old blog.

function torHttpGet($url, $ref) {  
$torIPPort="127.0.0.1:8118"; //tor's ip and port
$agentBrowser = array('Firefox','Safari','Opera','Flock','Internet Explorer','Ephifany','AOL Explorer','Seamonkey','Konqueror','GoogleBot');
$agentOS = array('Windows 2000','Windows NT','Windows XP','Windows Vista','Redhat Linux','Ubuntu','Fedora','FreeBSD','OpenBSD','OS 10.5');

$useragent=$agentBrowser[rand(0,7)].'/'.rand(1,8).'.'.rand(0,9).' (' .$agentOS[rand(0,11)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
$curl_obj = curl_init();
curl_setopt($curl_obj, CURLOPT_URL, $url); curl_setopt($curl_obj, CURLOPT_REFERER, $ref);
curl_setopt($curl_obj, CURLOPT_HEADER, TRUE); curl_setopt($curl_obj, CURLOPT_HTTPGET, TRUE);
curl_setopt($curl_obj, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_obj, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_obj, CURLOPT_MAXREDIRS, 3); curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_obj, CURLOPT_TIMEOUT, 10); curl_setopt($curl_obj, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl_obj, CURLOPT_PROXY, $torIPPort); curl_setopt($curl_obj, CURLOPT_CURLOPT_ERRORBUFFER, TRUE); //human readable errors
$page = curl_exec($curl_obj);
$err = curl_error($curl_obj);
curl_close($curl_obj);

if(strlen($err) > 0)
return -1;
else
return $page;

}

]]>

cat /etc/about-me

@calderpwn spends peaceful days in Cozumel, a beautiful island in the Caribbean, working on remote projects, learning new technologies, developing new tools, or simply enjoying the beach.

Join the mailing list

Stay updated with the latest tips and other news of my developments by joining the newsletter. It is very low volume, I promise :)