Created
April 16, 2011 18:05
-
-
Save memphys/923354 to your computer and use it in GitHub Desktop.
fetch some url through tor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Fetcher | |
{ | |
private $_torIp = '127.0.0.1'; | |
private $_torProxyPort = '8118'; | |
protected function _request($url) | |
{ | |
$res = curl_init(); | |
curl_setopt_array($res, array( | |
CURLOPT_PROXY => $this->_torIp . ':' . $this->_torProxyPort, | |
CURLOPT_CONNECTTIMEOUT => 10, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_URL => $url, | |
CURLOPT_HEADER => false, | |
)); | |
$response = curl_exec($res); | |
if (curl_getinfo($res, CURLINFO_HTTP_CODE) != '200') { | |
return false; | |
} | |
curl_close($res); | |
return $response; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Tor | |
{ | |
private static $_torIp; | |
private static $_torPort; | |
public static function newIdentity() | |
{ | |
$fp = fsockopen(self::$_torIp, self::$_torPort, $errno, $errstr, | |
if (! $fp) { | |
return false; | |
} | |
fputs($fp, "AUTHENTICATE\r\n"); | |
$response = fread($fp, 1024); | |
list($code, $text) = explode(' ', $response, 2); | |
if ($code != '250') { | |
return false; | |
} | |
fputs($fp, "signal NEWNYM\r\n"); | |
$response = fread($fp, 1024); | |
list($code, $text) = explode(' ', $response, 2); | |
if ($code != '250') { | |
return false; | |
} | |
fclose($fp); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment