Wordpress Comment Spam

Wordpress Comment Spam

Vinny O’Hare and Missy Ward had a conversation on Twitter today about blocking spammers by IP, something I’ve done for a while. But how do you know when to block an IP, and when to just mark the comment as spam and move on?

@missyward We have been banning IP’s at the server level due to spam. Seems to help a lot ask @loxlyless than a minute ago via HootSuite

First of all, if you don’t have Akismet installed, you’re just asking for trouble. I up the challenge a bit by requiring a captcha to be answered with the reCAPTCHA plugin. Even so, some spam still gets submitted and most of the time flagged as spam by Akismet. To ban repeat offenders by IP, do the following:

First, find those who repeatedly spam you. Run this SQL query:

SELECT count( * ) AS nCnt, comment_author_IP FROM wp_comments WHERE comment_approved = 'spam' GROUP BY comment_author_IP ORDER BY nCnt DESC

What you’ll get back is a table of those who spam you, ordered by how many times they spammed you:

Wordpress Comment Spam Count

Wordpress Comment Spam Count

Now you can see who spams you the most, and decide if you want to block those IPs. Let’s say I want to ban 178.32.81.224. I download my .htaccess file, and open it in a plain text editor. Then, at the very top, add:

order allow,deny
deny from 178.32.81.224
allow from all

Now if the user from 178.32.81.224 comes back, they’ll get a 403/Forbidden response, banned from my site forever.

Sure, they can get another IP, but since they spammed me 6 times from this same IP, I’m sure numbers 7, 8, and 9 are right around the corner. But, not anymore.

What else do you do to stop spammers from commenting on your blog? Oh, and no spam comments, please 🙂


4 Comments » for Blocking Spam Comments By IP
  1. Dino Vedo says:

    Thanks for the tip but I would think most spammers rotate their IP’s now a days… I know I do 😉

  2. Vinny O'Hare says:

    I feel honored to be mentioned in your post! Glad to be a blog post topic 🙂

    We were having problems on one of my sites and one of Debbies forums and cutting off the IP at the server level cut down spam by a ton. I want to say 90% of the bad guys were stopped, that number may be a little high but it sure did work.

  3. Tricia says:

    I like this post because it is a most helpful way to learn about the subject that you are writing about. Thank you for your writing on a most important subject.

    Oh, wait. You said do NOT spam your comments. Did I just get myself IP blocked?

  4. Matt Pardo says:

    Very cool, Eric. I didn’t know about that table. I currently use Akismet as well, but I still get a ton of spam. I am not sure if it is the host I am on or what. Anyway, I took this one step further by writing a little script to automatically update .htaccess. It is here if you are interested: http://www.affiliatepathfinder.com/blocking-comment-spam-leveraging-eric-nagels-post/

2 Pings/Trackbacks for "Blocking Spam Comments By IP"
  1. […] point is that I read a lot of blogs. Anyway, Eric Nagel posted a cool way to block comment spammers on his blog which is one of the blogs I […]

  2. […] reading Eric Nagel’s Blog entry about blocking spammers by IP I also happened to be working on cleaning up some of my […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*