mic2100 / is-tor
Detects whether the current visitor accessing your site from a Tor network exit point
dev-master
2015-06-13 01:46 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-12-21 20:15:49 UTC
README
Detect whether a visitor is accessing your site from the Tor network.
Usage
Getting the Tor ip addresses
$filename = sys_get_temp_dir() . '/ips.ip'; $storage = new Storage\FileStorage; $engine = new Engine; $subscriptions = new Subscriptions($engine, $storage); $assessor = new Assessor($engine, $storage); //This needs to be run from within a cron job so that the file is kept up to date //ip address of the server $ip = '11.12.13.14'; $subscriptions->addSubscription(new Tor($ip)) ->setName($filename) ->retrieve();
Checking the user
$filename = sys_get_temp_dir() . '/ips.ip'; $storage = new Storage\FileStorage; $engine = new Engine; $subscriptions = new Subscriptions($engine, $storage); $assessor = new Assessor($engine, $storage); //This needs to be ran on each of the requests that are received from users //Ideally the isTor method responses can be cached in APC (or other caching system) $ip = $_SERVER['REMOTE_ADDR']; if ($assessor->setStorageName($filename)->isTor($ip)) { //the current visitor is accessing your site through the Tor network } //the current visitor is not accessing your site through the Tor network