mic2100/is-tor

检测当前访问者是否通过Tor网络出口点访问您的网站

dev-master 2015-06-13 01:46 UTC

This package is auto-updated.

Last update: 2024-09-21 19:35:11 UTC


README

检测访问者是否从Tor网络访问您的网站。

使用方法

获取Tor IP地址

$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();

检查用户

$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

Bitdeli Badge