V
V
votod2015-09-20 22:37:01
PHP
votod, 2015-09-20 22:37:01

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

3 answer(s)
V
votod, 2015-09-20
@votod

<?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

G
GavriKos, 2015-09-20
@GavriKos

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."

D
Dmitry, 2015-09-20
@2fox

php.net/manual/en/function.stripos.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question