Welcome to The Blog Report

I'm so glad you stopped by and hope you find this blog an interesting read. I've been blogging since April of 2006, currently the author of six public and two private blogs. In the beginning I knew absolutely nothing about blogging. Over the years through trial and error, frustration and elation, and a few tears I've learned a lot. However, the learning process when it comes to blogging continues to evolve. Here you will find a hodge podge of my blogging experiences, useful codes and how-tos, sprinkled liberally with my opinions. Enjoy!

Search this blog:

Friday, July 30, 2010

Blocking an IP with PHP

At some point you may have the need to block one or more persons from reading your blog but the problem isn't severe enough to warrant making your blog private.  This is particularly desirable if you end up with a persistent comment spammer.  Blogger does not make this easy because there is no access to the .htaccess file and to date despite requests Blogger has not made an IP blocker available.  The block can be in javascript (JS) or PHP format.  You can add a JS gadget in your element layout that will effectively block one or more IP addresses.  The problem with using JS is a user can simply diable JS to circumvent the script so they can still get through to your blog.  I found the PHP code at Perishable Press (How to Block IP Addresses with PHP) and JS IP block code through Javascript Kit.  The nice thing about the PHP code is it will work even if JS is turned off.  You can modify the code in either to send the unwanted visitor to any site of your choice. 

Quite frankly it really doesn't matter where you send them but the generic send to Google won't give them any idea of what you did if you use the PHP code.  If you use the JS code you can give them a flip off message that they have been banned from your site..  If the unwanted visitor tries to access through an IP anonymizer then simply add the IP of the anonymizer as well.  Now if a comment spammer is really persistent they can still get around this by using a computer at a different IP.  In this case resort to tracking in your stats to identify the IP then add that IP to the block as well.  Essentially what you are doing is setting up call block but instead of for your phone you are doing it to your blog.  Once the comment spammer realizes s/h/it can't get through they will move onto greener pastures.  You can leave the IP block on and modify as needed.  Chances are good that you may only need to take this step once because persistent comment spammers are thankfully few and far between.  I think it is a handy bit of coding to save just in case it is needed.


Post a Comment

Thank-you for your comment. It will appear once approved.