This question already has an answer here:
I'm getting spammed pretty hard and trying to stop it… I have a code similar to this to grab IPs and then block them but also trying to add this code to block anyone visiting my site with a host that starts with the string 'tor'. What comes after that varies greatly, so only want to match the first three letters and then block…
<?php
// The function to get the visitor's IP Host info.
function getUserHostIP(){
//check ip host from share internet
$blackListHost=gethostbyaddr($_SERVER['REMOTE_ADDR']);
if (strpos($blackListHost, 'tor') === 0) {
header("Location: unauthorized.php");
die();
}
}
//The user
getUserHostIP();
?>
</div>