Example #1
0
$torcurl->setopt(CURLOPT_HTTPHEADER, array('Accept-Language: en-US,en;q=0.5', 'DNT: 1', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'));
// uncomment the follow lines to show verbose output from curl
//$torcurl->setopt(CURLOPT_VERBOSE, true);
//$torcurl->setopt(CURLOPT_STDERR, fopen('php://output', 'w'));
try {
    $torcurl->httpGet('https://check.torproject.org/');
    echo sprintf("Request to %s returned HTTP %d.<br><br>\n\n", $torcurl->getInfo()['url'], $torcurl->getHttpStatusCode());
    // show response headers in textarea
    echo "Response Headers:<br>\n<textarea style='width: 500px; height: 140px'>";
    foreach ($torcurl->getResponseHeaders() as $header => $value) {
        // loop over each header
        echo "{$header}: {$value}\n";
    }
    echo "</textarea><br><br>\n\n";
    // show response body in textarea
    echo "Response Body: (Content-Type: " . $torcurl->getInfo()['content_type'] . ")" . "<br>\n<textarea style='width: 98%; height: 500px'>" . htmlspecialchars($torcurl->getResponseBody()) . "</textarea><br><br>\n";
    //print_r($torcurl->getInfo());
    // Example post:
    /*
    $torcurl->httpPost(
        'http://example.com/form',
        http_build_query([ 'name' => 'Your Name', 'email' => 'Your Email', 'message' => 'Hello!' ])
    );
    // OR (sample file upload using CURLFile [PHP >= 5.5])
    $torcurl->httpPost(
        'http://example.com/upload',
        [
            'action' => 'upload',
            'name'   => 'Your Name',
            'file1'  => new CURLFile('/path/to/img.jpg', 'image/jpeg', 'file1'),
            'file2'  => new CURLFile('/path/to/img2.jpg', 'image/jpeg', 'file2'),
Example #2
0
<?php

require '../src/ControlClient.php';
require '../src/TorCurlWrapper.php';
// list of country codes to use
$countries = array('US', 'FR', 'RU', 'GB', 'CA');
// get new control client for connecting to Tor's control port
$tc = new Dapphp\TorUtils\ControlClient();
$tc->connect();
// connect
$tc->authenticate('password');
// authenticate
foreach ($countries as $country) {
    $country = '{' . $country . '}';
    // e.g. {US}
    $tc->setConf(array('ExitNodes' => $country));
    // set config to use exit node from country
    // get new curl wrapped through Tor SOCKS5 proxy
    $curl = new Dapphp\TorUtils\TorCurlWrapper();
    $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox 41.0');
    // make request - should go through exit node from specified country
    if ($curl->httpGet('http://whatismycountry.com')) {
        echo $curl->getResponseBody();
    }
}