Monday, August 17, 2009

How to Block users From Visiting Your Blogger Blog

Some time you will notice that certain IP users are visiting and performing some unwanted ( spam ) activities. This can be tracked using a tracker placed in your website/blog. Then the noted IP can be used to block or literally ban users from visiting your blogger blog. This trick is Implemented using JavaScript and PHP.

How to Block users From Visiting Your Blogger Blog

Login into your Blogger Dashboard >Edit HTML
As I always say before attempting any tutorial or hack its wise to make a backup of your blogger template. So please download your blogger template.

Locate <head> in your blog template. And paste the following code just at the beginning of your blog's <head> tag.


<script type="text/javascript" src="http://code.vietwebguide.com/php/addr.php"></script>
<script type="text/javascript">
//&lt;!CDATA[
// Banned ip script 2.0
//(C)2009 Anhvo
//homepage: http://vietwebguide.com

var banned_ip = new Array();

banned_ip[0] = '85.142';
banned_ip[1] = '22.98.69.1';
banned_ip[2] = '22.98.69.146';
banned_ip[3] = '85.78';

var mes_bi = "Your IP is banned so you cannot visit this website!";

for(var i=0;i&lt;banned_ip.length;i ) {
eval('var re = /^' banned_ip[i] '/ ;');
if (re.test(mc_user_ip))
{
document.write('&lt;style type="text/css"&gt;');
document.write('BODY{display:none;}');
document.write('&lt;\/style&gt;');
alert(mes_bi);
break;
}
}
//]]&gt;
</script>


Replace the IP ranges from the above code with the IPs of the visitors you want to keep out of your blog. Example: If you want to block all IPs in the range '11.22.XXX.XXX', simply add "11.22" as the IP number in the above code.

Note: if entering the above code into your template returns the following error: "XML error message: The content of elements must consist of well-formed character data or markup.", use the code from this website (exactly as it is given) instead of the code given above.

Thank you for reading: "How to Block users From Visiting Your Blogger Blog" You can also get a free subscription to Chethstudios updates. We will be back with more useful content. Get latest hacks and updates on your email

15 comments:

  1. I used the code to block the range, and she is still able to comment on my blog (she is a a psycho troll who now makes me moderate my comments.)
    And when I enter the addresses into blogger, blogger automatically attaches an ampersand {&} and the number 39 before and after each address.

    ReplyDelete
  2. vietwebguide.com always provide many useful blogger tricks and scripts, thanks cheth

    ReplyDelete
  3. hey great post,though not implemented in my blog,but a great idea

    ReplyDelete
  4. Cheth, you have no idea how much time you have saved me with this. I tested it with my own IP to see if it will work, and it did. I had used Toolator before, but for some reason, it no longer works on my page.

    Once again, your work and help for bloggers is appreciated! Thanks!

    ReplyDelete
  5. oh HELP.... tried the code ... saves fine without any error message but tried to test by blocking my own IP and it doesn't work!

    I have some one I HAVE to block or shut down completely as they are taking my work! And I WON'T won't won't let that happen anymore!

    ReplyDelete
  6. @Anonymous

    It works, please check out the previous comment by @David Funk he too had this trick to work on his blog.. I think you did a mistake.. kindly let me know which is your blog?

    ReplyDelete
  7. What about new control for user to block another users in blog site? I am tried to looking for plugin to help users to have good control to delete comment or block users, etc.

    ReplyDelete
  8. the first code didnt work for me so i went to the other site, used the second code at the bottom , and problem is , it worked to well lol , it redirected and banned everyone ! do u have a fix for it ?

    ReplyDelete
  9. Are there any script to block referal sites?

    ReplyDelete
  10. I tried both codes which redirects visitors to your page. Your code seems not good-mannered.

    ReplyDelete
  11. update: this code used to work perfectly earlier... but it isn't working the desired way. I will try to work out a fix to it.

    ReplyDelete
  12. Maybe you can get it's original source code from that page (http://code.vietwebguide.com/php/addr.php) and modified it, so i can place it on my desired host and redirect troll to my desired page, it helps me a lot in earlier time.

    Your work and help for bloggers is appreciated! Thanks Cheth.

    ReplyDelete
  13. Hey Cheth, I tried the code. If I put it right after the -head- it redirects everyone but if I put it after the meta tags in the head is block no one and I did test my IP but it didn't work. Using the corrected code for xml keeps giving an xml error. Please help.

    ReplyDelete
  14. The script src http://code.vietwebguide.com/php/addr.php has not working any more can you provide the code directly.

    ReplyDelete

Please Don't Spam that's all. Grab our RSS Feed and we would Love to see you in our comments section more often.