image



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.
Fortunately, there are various measures to minimize spammers and trolls on your blog, and this simple PHP tutorial is one of them. All you need to know is the IP address of the particular spammer or troll.
The instructions are as follows:
  1. Copy/paste the PHP code below in a notepad
  2. Replace IP Address 1, IP Address 2, and IP Address 3 with the actual IP addresses you want blocked
  3. Save the file as a .php file (ex. ipblocker.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 like 000webhost.com and zymic.com
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 A:
  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 B:
  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.

0 comments:

Post a Comment

 
Top