How To Block a specific IP address from accessing your website or blog


Dealing with spammers and trolls is already a given when it comes to running a 
website. There’s just almost no way to completely avoid them, but that doesn’t 
mean that you have to put up with them and let them keep on disturbing the 
peace on your site.
The instructions are as follows:
1.Copy/paste the PHP code below in a notepad

2.Replace IP Address 1, IP Address 2, IP Address 3 and so on with the 

   actual IP addresses you want blocked
 
3.Save the file as a .php file (ex. ipblock.php)

<?php
/*
Blogspot IP address blocker.
*/
$iplist = array(“IP Address 1″,”IP Address 2″,”IP Address 3″,...); 
// the list of banned IPs
$ip = getenv(“REMOTE_ADDR”); // get the visitors IP address
// echo “$ip”;
$found = false;
foreach ($iplist as $value) { // scan the list
if (strpos($ip, $value) === 0){
$found = true;
}
}
if ($found == true) {
echo “top.location = “error.html”;n”; // page to divert to
}
 ?>

4. Upload your newly created PHP file on any PHP supported web hosting service.

5. Lastly, paste the following code in your Blogger or Blogspot blog



<SCRIPT LANGUAGE=’javascript’ SRC=’BlogspotIPblocker.php’ 
     TYPE=’text/javascript’></SCRIPT>

There are 2 methods by which you can do this:

METHOD 1:
  1. Go to the ‘Design’ section of your Blogger dashboard.
  2. Under ‘Template’, click on ‘Edit HTML
  3. Look for the </head> tag and paste the code before it.
METHOD 2:
  1. Go to the ‘Design’ section of your Blogger dashboard
  2. Under ‘Layout’, click on ‘Add a Gadget
  3. Scroll down and select ‘HTML/JavaScript’ and paste the code inside the ‘Content’ box
  4. Save the gadget.
And that’s it! Next time the user spammer or troll tries to visit your page, they won’t be able to access it and will receive a custom message.

Comments