Answer the question
In order to leave comments, you need to log in
How to block the tor network?
<?php
$hostname = gethostbyaddr($_SERVER['HTTP_CF_CONNECTING_IP']);
if ($hostname == ' tor ') {print "You don't have permission!";exit;}
?>
Where is the error here? I need it to block if the hostname contains the word tor
. If you write the hostname in full, then it blocks, but I need it a little differently as I wrote earlier.
Answer the question
In order to leave comments, you need to log in
<?php
$string = gethostbyaddr($_SERVER['HTTP_CF_CONNECTING_IP']);
if(stristr($string, 'tor')) {echo 'Tor network is blocked';exit;}
?>
Working php script.
HTTP_CF_CONNECTING_IP this is used because site is proxied through cloudflare.com
The error is that you are checking for an exact match, not for a substring within a string. In Google and search - "php search for a substring in a string."
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question