PHP - IP Page Blocker
From Global Programming Syntax
When making a website, depending on what content you have, you may not want some people to view some of your webpages. If you have those peoples ip addresses then you can put a list of ip addresses into a text file and use the following script to read the text file and block those ip addresses. So place the following piece of code at the very top of the file and is important you do that if you want this script to work.
<?
$data=file_get_contents('ipaddresses.txt');
$ip=explode('
',$data);
$id=0;
while (isset($ip[$id]))
{
$ip2=explode(' ',$ip[$id]);
if ($ip2[0]==$_SERVER['REMOTE_ADDR'])
{
echo "<h2>Your ip address has been blocked.</h2>";
exit;
}
$id+=1;
}
Then after placing that code at the top of your php file(s), you then need a text file with the list of ip addresses. Also comments can be made after an ip as long as there is a space straight after the last number. Also it is best if comments are NOT on their own lines. You may want to note in the above script would be in a file called ipaddresses.txt in the same folder. So the list of ip addresses in the text file should look like the following:
123.163.0.321 some guy 127.0.0.1 localhost person 184.295.112.182 another random ip address
