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!
Please remember to replace the obvious with your real information,
e.g.
YOURAKISMETAPIKEYHERE = The API Key you have gotten from signing up to WordPress.com
http://www.yourforums.com/forums = URL of your forums
..and the email from & to names/addresses
Also please note that I made these mods to phpBB 3.0.5, so you may not be able to find some of the code if you’re using earlier versions, though I think it’ll probably be there in all previous 3.0.x versions
Hi Mark,
many thanxs.. this looks very promising.
Last days i am also dealing with shit loads of spam at my forums and it all seems to be manually entered spam.
i’ll try your solution and will let you know, how it goes…
One question please… How about the “phpBB3 mod called daroPL_AntiSpam”?
Do you actually use it along with your Akismet solution?
thanx
Yeah, I set up daroPL_AntiSpam to help prevent automated signups and my Akismet solution for people manually trying to spam
Hi Mark,
many many thanxs!!!
your solution works perfectly and akismet can catch about 98% of spam posts.
Really wonderful…
One idea, though..
it would be great, if you can also implement warnings and banning. Let’s say, after 1st spam post, warning will go to the user. After another spam post, user will get banned
one more time THANK YOU!
I highly recommend this to every one, using phpbb3. No more WOW gold and stuff like that.
Hi Mark,
after i’ve got tired of banning all those spammers on my board, i’ve extended the script a little bit, so it also bans on spam attempt.
Maybe it’s not very polished as it is now, but it works for me.
After mail call, in your script, i just added:
$sql = "INSERT INTO " . BANLIST_TABLE . " (ban_userid, ban_reason, ban_give_reason) VALUES (‘$uid’, ‘AutoBAN – posting SPAM’, ‘AutoBAN – posting SPAM’)";
$db->sql_query($sql);
$sql = "DELETE FROM " . SESSIONS_TABLE . " WHERE `session_user_id` = $uid";
$db->sql_query($sql);
which adds that user to banlist table and deletes his session, so he gets immediately logged of.
sorry, one more line code goes before that:
(int) $uid = $user->data['user_id'];
so the complete code looks like:
// 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(‘YOURAKISMETAPIKEY’,'http://YOURDOMAIN.TLD’);
if(!$akismet->error) {
if($akismet->valid_key()) {
if($akismet->is_spam($akismet_comment)) {
$this->warn_msg[] = $user->lang['AKISMET_SPAM'];
$a_to = "EMAIL@WHERETOSENDNOTIFICATION.EMAIL";
$a_subject = "Attempted SPAM Post by ".$user->data['username'];
$a_body = $this->message;
$a_headers = "From: EMAIL@NOTIFICATIONSENDER.EMAIL";
mail($a_to, $a_subject, $a_body, $a_headers);
(int) $uid = $user->data['user_id'];
$sql = "INSERT INTO " . BANLIST_TABLE . " (ban_userid, ban_reason, ban_give_reason) VALUES (‘$uid’, ‘AutoBAN – posting SPAM’, ‘AutoBAN – posting SPAM’)";
$db->sql_query($sql);
$sql = "DELETE FROM " . SESSIONS_TABLE . " WHERE `session_user_id` = $uid";
$db->sql_query($sql);
}
}
}
}