I want to block some hostnames and ips from accessing my website, I use this codde to =block only one hostname or ip:
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ipz = $_SERVER['REMOTE_ADDR'];
if ($hostname === "blocked hostname" || $ipz == "blokced ip" ){
echo "redirect to some url";
}
else {
echo "show site content";
}
?>
But I have a long list hof hostnames and IPs to be blocked, I want to add all those bad IPs and hostnames I have in a separated file, and then check if the visitors hostname or IP is on that list or not.
how can I do that and keep to site loading fast ?
Thanks
First way, put all your ip in a single file, separated by a newline. Then, you’ll do :
If you need more info about file() flags, you can read this.
For security reasons, you may put your “ips.txt” file in a folder unavailable from the outside.
Second way, you have a sql table where all ips are stored :