Rectanglicle

The Personal Website of Ash M. White

Stop Comment Spam With Akismet

by Ash White / 10.29.09

SPAM
SPAM

"Remember the days before spam?" I barely can, but this slogan for Akismet might really hit home for some. Spam has become quite a nuisance for just about everybody who uses the Internet, not to mention the added trouble for those who run websites. Email spam, comment form spam, link spam, etc all add up to a force of nature that can be difficult to combat.

In the past I have always (begrudgingly) used CAPTCHAs to prevent comment form spam. Though effective, CAPTCHAs introduce another step of work for the visitor, potentially discouraging conversions. This risk rises significantly each time the user mistypes the response. Additional concerns include the issue of accessibility as well as the option for a dedicated spammer to manually submit a challenge response.

Akismet aims to make filtering easier by almost completely automating the spam identification process. This free service, which was started in October of 2005 as a plugin for WordPress, has filtered over 13 billion spam messages in its lifetime. The service is now included as part of every WordPress download and is activated on all hosted WordPress accounts. It works by combining spam information from all of the websites that use it, analyzing comments in real time when they are submitted, but before they are stored in the database. This removes the extra work from the user, detects manual spam that is not bot-generated, and can teach itself new rules based on new types of spam.

But what if your site doesn't use WordPress? No problem. Simply head over to the development section of the Akismet site and download the library that suits your environment. I recently began implementing the PHP 5 class provided by Aching Brain. The class is lightweight and usage is super simple. In your controller or CMS, just add the following code:

$WordPressAPIKey = 'APIKEY';
$MyBlogURL = 'http://www.example.com/blog/';

$akismet = new Akismet($MyBlogURL, $WordPressAPIKey);
$akismet->setCommentAuthor($comment->author_name);
$akismet->setCommentAuthorEmail($comment->author_email);
$akismet->setCommentAuthorURL($comment->author_url);
$akismet->setCommentContent($comment->comment_body);
$akismet->setPermalink($comment->url());

if($akismet->isCommentSpam()) {
	// store the comment but mark it as spam (in case of a mis-diagnosis)...
}
else {
	// store the comment normally...
}

In the event of a false positive, it's a good idea to still save spam comments and put them in an approval queue.

Categories

Tags

blog comments powered by Disqus
info

All work is original and copyright 2014 by Ash White, with the exception of a handful of free third-party libraries, including the Scriptaculous JavaScript framework, Lightbox image overlay, Google Font Directory, Google Code Prettify, and Eric Meyer's CSS Reset.