PHP code to get user IP and compare to others in a file, and ban if they match.
This code snippet will read the IP’s from the txt file with your IP’s listed that you would like to ban, this code will check the visitors IP and compare it to your list if same ip in the text file than they will be banned.
How to;
1. Insert the code snippet to your php page.
2. Create a text file called ( IP.txt ) and fill it with the ip’s that you would like to ban, make sure each ip is on its own line.
Note: make sure your path to text file is reflected to the code.
$ip = $_SERVER['REMOTE_ADDR'];
$ipArray = preg_replace("#\r\n?|\n#","",file('IP.txt'));
foreach ($ipArray as $ipTest) {
if (substr_count($ip, $ipTest) != "0") {
header('location: http://google.com');
die();
}
}

























