Pete Freitag Pete Freitag

How I block comment spam


You would think that by having custom written blogging software (only two other blogs out there are using this code), and not allowing HTML in comments, that comment spammers would not waste their time on me. But they do.

Why do they bother with me?

Even though their URL will not be hyperlinked on my blog giving them pagerank, they still spam because they are hoping for the following:

  • They want me to click on the link before I delete it.
  • They are hoping that people subscribed to the comment thread will click on the link.
  • They are planting keywords on my pages so that someone searching for the term in google, may find my page, and copy and paste the url.

When I was at the bloggers BOF at cfunited, people mentioned that when using Ray Camden's blog CFC software they didn't get much if any comment spam. I think that is because the comment form is located in a popup window launched by javascript. So it's more of a hassle for spammers to spam them. I however would rather keep my comment form on my entry page, so it's easier for readers to post comments.

What I do to block comment spam

Here's what I do to block comment spam on this blog:

  • Check HTTP Referrer to make sure it's coming from my site. I know some people like to turn this off in their browser, but they won't be able to post comments unless they turn it on.
  • If the comment contains a HTML link I reject it, giving the user a detailed message that tells them to just post the url.
  • Check for a set of bad words - my list is very small only about 10 words currently.
  • Check for [url] - a lot of comment spammers try to pass the links as [url]http://foo[/url]
  • Look for more than 5 url's in the comment. Comment spammers often try to post 10-20 urls at a time, so I just reject them. I use this regular expression REFindNoCase("(http:.*){5,}", form.comment)

Like this? Follow me ↯

How I block comment spam was first published on July 19, 2005.

If you like reading about blog, spam, or comment spam then you might also like:


by fredo on 07/19/2005 at 5:13:55 PM UTC
I was having the problem as well (using my own custom Blog software.) I fixed this by building a simple spam filter. When I get a piece of spam, I move it to a spam filter table. All my spam was coming in from basically the same e-mail address and the same Urls, so my filter basic looks to see if these is a bad comment and if so silently rejects it.

While I was getting a handful of spam messages a week, I've dropped down to zero.
by Dan G. Switzer, II on 07/19/2005 at 7:31:03 PM UTC
A small modification to your regex to deal with https and to make it non-greedy.

REFindNoCase("(https?://.*?){5,}", form.comment)
by Michael Dinowitz on 07/19/2005 at 11:51:08 PM UTC
I have been looking for sites like this for a long time. Thank you!
by All about stock market on 10/20/2006 at 9:07:07 PM UTC
I visited your web site.
by Attorney for you on 10/22/2006 at 11:50:21 PM UTC
Thank for making this valuable information available to the public.
by alex on 07/31/2007 at 1:53:57 AM UTC
very helpful, thanks!n
by Tim on 08/27/2007 at 2:20:09 AM UTC
Very good web site, great work and thank you for your service.+
by Tim on 09/27/2007 at 8:09:23 AM UTC
excellent texture.l
by yamomoto on 10/03/2007 at 12:15:54 PM UTC
While I did get some good's funny to see that this page has been spammed quite a bit. Pretty much everything after Oct 20, 2006 is junk.
by karl krist on 07/09/2008 at 10:42:19 AM UTC
Apple Inc.'s new data synching service got off to a rocky start Thursday, as some users were denied access to their accounts just hours before the next-generation iPhone is slated to go on sale.
by TessrTorn on 07/15/2008 at 5:31:05 AM UTC
H0QzIh Thanks for good post
by johnny on 12/29/2008 at 11:10:57 AM UTC
Totally Awsome!
by mature on 09/29/2009 at 9:52:25 PM UTC
Totally Awsome!
by prison on 09/30/2009 at 10:11:15 PM UTC
Thanks for the good information.

Pls tell me where to place that code in Word press sites
by peter on 06/24/2010 at 5:56:35 AM UTC
hi there stevo if you are still in need of them i think this is the contact
and some info , there very helpfull ,tell them micky h give you there number
by michaelhimpson on 06/23/2012 at 12:31:32 AM UTC