Answer the question
In order to leave comments, you need to log in
How to check if a site visitor is using the Onion network?
Where can I get fresh lists of onion-relays?
Answer the question
In order to leave comments, you need to log in
Here is a working example
function isTorUser($ip)
{
$list = getTorExitList();
if (arrayBinarySearch($ip, $list) !== false) {
return true;
} else {
return false;
}
}
function getTorExitList()
{
$path = __DIR__ . '/tor-list.cache';
if ( file_exists($path) && time() - filemtime($path) < 600 ) {
$list = include $path;
if ($list && is_array($list)) {
return $list;
}
}
$data = file('https://openinternet.io/tor/tor-node-list.txt');
if (!$data) {
return array();
}
$list = array();
foreach($data as $line) {
$line = trim($line);
if ($line == '' || $line[0] == '#') continue;
list($nick, $ip) = explode("\t", $line);
$list[] = $ip;
}
sort($list);
file_put_contents($path, sprintf("<?php return %s;", var_export($list, true)));
return $list;
}
function arrayBinarySearch($needle, $haystack)
{
$high = count($haystack);
$low = 0;
while ($high - $low > 1){
$probe = ($high + $low) / 2;
if ($haystack[$probe] < $needle){
$low = $probe;
} else{
$high = $probe;
}
}
if ($high == count($haystack) || $haystack[$high] != $needle) {
return false;
} else {
return $high;
}
}
$isTorUser = isTorUser($_SERVER['REMOTE_ADDR']);
if ($isTorUser) {
Die("Извините, но Вы не можете пользоваться нашим сайтом из сети TOR!!!");
}
https://gist.github.com/jeroenvisser101/cb7e01f58b...
I don't know if this option still works, it worked before.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question