May
9
2007
IP and referrer blocking

In my ongoing effort to stop comment spam from getting through, I've decided to implement IP address blocking and referrer blocking. I never really wanted to block IP's or visitors from certain referrers from accessing my entire site, but decided to build a little script to do so anyways. I guess I should start being a little tougher on these spambots.

The page that blocked IPs and referrers see

So creating this was pretty simple. I first just created a new table in my MySQL database with a unique id field, IP address field, referrer field, active field, reason field, and datetime field. Each row will either contain info in the IP address field or the referrer field as well as the others. The active field is just a little flag where I can enable or disable the ban on the IP/referrer. The reason field is just a text field where I can type in a reason as to why I created this block in the first place. And the datetime field is just a timestamp of when the block/ban was created.

Next I just created a script on my admin page where I could easily add, edit, and delete items in this database table. Finally, I just had to implement this block/ban on the main site, and since my blog runs on a template system, doing this was easy. I just edited my main template script and put a if/else statement in there. For example, if the visitor's IP address or referred is in the database table and active, then redirect them to the blocked.html page (seen above), else execute the template script like normal.

So far, this has worked great. The spambots that were still getting through my various anti-spam techniques all had the same IP address or came from the same referrer. So I simply added that IP and referrer into the database and I haven't seen a spam comment from them since *knock on wood*. I'm sure it's only a matter of time before they realize this and change their IP address or use a different referrer, but what the hell, at least it stopped them for the time being.

Author's Pic
// Article Summary
This article was published 1 year 2 months ago on Wednesday, May 09, 2007 2:37 pm by Nick Villescas. It was published under the following topics: Programming, Site News and with the following tags: coding, MySQL, PHP, spam. So far this article has received 221 hits with 2 comments.
2 comments
1 year 2 months ago // May 10, 2007 8:35 am
Jet Andre // guest

Gravatar
Maybe if they still get through, you need to bring back the thing where you have to type in the number/letter code thing to post.
1 year 2 months ago // May 10, 2007 2:50 pm
Nick Villescas // author

Gravatar
It's called the captcha. A lot of people just don't like that thing, including myself. But that's really the only method I've come across that works 100% at blocking spam.

Another issue with the captcha right now is my damn host. They keep breaking the Imagemagick binaries, which I use to build that random image. It's broken again right now and they have yet to fix it. So even if I wanted to enable right now, I couldn't.
Add your comment
// required


Allowed Tags // <a><ul><ol><li><strong><em><blockquote> // required


This form is protected from spam by Akismet. Comments are Gravatar enabled and also moderated.