Akismet SPAM Filtering in phpBB3
Recently I’ve been seeing a shitload of Spambot signups and actual spam postings on my Coopersguns BodyBuilding forums
phpBB 3 had a little spam hiatus whilst the spammers cracked the new captcha system, however it’s obviously been well and truly broken now
I decided to clean the forums up and get rid of the spammers. I have employed 2 techniques:
- A phpBB3 mod called daroPL_AntiSpam
- Some code I quickly conjured up to check with Akismet when a comment is posted
I will obviously be talking about the latter here, follows are instructions on how to implement the Akismet check on posts:
If you want to copy & paste the following code snippets, hover over them and click the ‘copy’ button
1) Download akismet-php-curl-class
2) Copy the akismet.curl.class.php from the archive to your phpBB3 forum’s ‘includes’ folder (e.g. ~/public_html/forums/includes)
3) Edit message_parser.php in the ‘includes’ folder and make the following changes:
Find:
if (!class_exists('bbcode'))
{
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
}
After it, insert the following
if (!class_exists('akismet')) {
include($phpbb_root_path . 'includes/akismet.curl.class.' . $phpEx);
}
Find:
// Check number of links
if ($config['max_' . $mode . '_urls'] && $num_urls > $config['max_' . $mode . '_urls'])
{
$this->warn_msg[] = sprintf($user->lang['TOO_MANY_URLS'], $config['max_' . $mode . '_urls']);
return (!$update_this_message) ? $return_message : $this->warn_msg;
}
After it, insert the following:
// Akismet SPAM check
if (($user->data['user_posts']<=6) && ($user->data['user_type']==0)) {
$akismet_comment = array(
'comment_type' => 'comment',
'comment_author' => $user->data['username'],
'comment_author_email' => $user->data['user_email'],
'comment_author_url' => $user->data['user_website'],
'comment_content' => $this->message,
);
$akismet = new akismet('YOURAKISMETAPIKEYHERE','http://www.yourforums.com/forums');
if(!$akismet->error) {
if($akismet->valid_key()) {
if($akismet->is_spam($akismet_comment)) {
$this->warn_msg[] = $user->lang['AKISMET_SPAM'];
$a_to = "you@youraddress.com";
$a_subject = "Attempted SPAM Post by ".$user->data['username'];
$a_body = $this->message;
$a_headers = "From: admin@yourforums.com";
mail($a_to, $a_subject, $a_body, $a_headers);
}
}
}
}
4) Edit posting.php in the ‘language/en/’ folder (obviously you’ll need to add this to other languages your users use too)
Find:
'TOO_FEW_CHARS' => 'Your message contains too few characters.',
After it, insert the following:
'AKISMET_SPAM' => 'Your message looks like SPAM.',
5) Finished!