Depending on your configuration, the script may need to authenticate before it can signal TOR to switch to a new identity.

There are three authentication modes TOR supports :

None – no authentication required. You don’t need to set the third parameter of tor_new_identity().

Cookie – TOR stores a “magic cookie” in the control_auth_cookie file inside it’s data directory. You have to authenticate by sending this cookie encoded in hexadecimal form. You can use tor_get_cookie() to read and properly encode the cookie.Example :