Hi,
I am having a similar problem. I am working on win7-64 bit with WAMP 2.1. I am trying to do basically the same thing with the latest Vidalia ( including Tor 0.2.1.30 and Polipo ), running locally. I am using php 5.3
<?php
?
//include the class
//remember the configuration file is located in:
//proxyConfiguration.ini
include("./proxyConnector.class.php");
//get an istance of the proxy
$connection = proxyConnector::getIstance();
//connect to google.com and change my identity
//because "switchIdentityAfterRequest" is set to TRUE
//in the .ini file
$connection->launch("http://whatismyip.com", null);
//get the data and show it
$data = $connection->getProxyData();
echo "<pre>";
print_r($data);
The class is attached.
My problem is that , I would like to switch Identity after each request ( I am querying http://whatismyip.com ) . this happens sometimes, but when I run my script too close together , temporally, the IP address does not switch ( If I wait longer it will ). The following code snippet is running without obvious error when I step through it with xdebug:
/**
*
* Change identity in the Tor Network
* (change public IP Address)
*
* @return bool
* true is new identity is created
* false is fail creating a new identity
*/
public function newIdentity(){
$fp = fsockopen($this->ip, $this->controlPort, $errno, $errstr, 30);
if (!$fp) return false; //can't connect to the control port
fputs($fp, "AUTHENTICATE ".$this->controlPassword."\r\n");
$response = fread($fp, 1024);
list($code, $text) = explode(' ', $response, 2);
if ($code != '250') return false; //authentication failed
//send the request to for new identity
fputs($fp, "signal NEWNYM\r\n");
$response = fread($fp, 1024);
list($code, $text) = explode(' ', $response, 2);
if ($code != '250') return false; //signal failed
fclose($fp);
return true;
}
I think that some cacheing may be going on somewhere, or a connection is being maintained when it should not . As a php beginner, I don't know how to test this or where to look. I would appreciate any help.
Thank you in advance,
KC
PS - here is the ini file - I couldn't attach it
; this is the ini file for the proxy configuration
; this default value are for a TOR PROXY running
; on a local machine with HashedControlPassword method
; activated
[general]
; timeout
timeout = 300
; proxy ip
ip = 127.0.0.1
; proxy port (default value stands for polipo port)
port = 8118
[TOR]
; proxy control port
; be sure to enable control in your
; tor configuration file (/etc/tor/torrc)
controlPort = 9051
; the password setted in the HashedControlPassword
; set a tor control password with:
; tor --hash-password YOUR_STRONG_PASSWORD
;
; To use this default configuration file try:
; tor --hash-password t0rS3cr3tPwD
;
; left blank if you have configured TOR CONTROL PORT
; without a password
controlPassword = t0rS3cr3tPwD
; if true after every request the class try to change
; his identity and his userAgent
switchIdentityAfterRequest = true
[attachment deleted by admin]