Stopping spam bots.

JosephC

Paragon
Joined
Aug 22, 2009
Messages
1,703
Reaction score
1
FP$
599
Just a little tip to help stop spam bots. The coding isn't very clean so you may want to tidy it up, but it works as is so you don't have to if you don't want to.

This uses the stopforumspam API and blocks bots or other spammers (that are listed) from your forum before they can even view the header. There's not a limit on the API usage so you don't have to worry if you have a big forum.

Firstly in your forum style overall_header put an include to a file called spamCheck.php or something, so it'll be <!-- INCLUDE spamCheck.php -->, if that doesn't work go into your phpbb settings and enable PHP code in templates, then use <!-- PHP -->include("spamCheck.php");<!-- ENDPHP --> (Not sure on the syntax here, but the actual code to check I'm 100% sure.)

Then create a file called spamCheck.php in your styles/style_name/template folder.

And put the following in it:
Code:
<?php
session_start();
if(!$_SESSION['spam_check']){
$check = file_get_contents("http://stopforumspam.com/api?ip=".$_SERVER['REMOTE_ADDR']);
if(stristr($check,"yes")){
$_SESSION['spam_check'] = "yes";
}
else {
$_SESSION['spam_check'] = "no";
}
}

if($_SESSION['spam_check'] == "yes"){
die("Your IP is listed as spam. Please visit http://stopforumspam.com to get yourself removed.");
}
?>

What this does is, if there's no spam_check session it'll then perform the check, and assign either yes or no. Yes is obviously that they're a spammer, and every time they visit the site they'll get the spam message, and die() will have it end the code there so no further actions are performed (i.e the forum displaying).

If they then clear cookies, sessions, etc.. it'll do the check again so there's no way around it. You could make it so instead of ['spam'] = "no"; it just doesn't set it, but this is unnecessary connections to their service.

Again. This is NOT clean code so the messages about it aren't needed 🙂 It's just helpful as most of the spam modifications just block posts or registrations, this will block them from seeing the forum completely.

This also works on websites that have spam bots commenting on blog posts, submitting email forms, etc.. just use this code in the global header (I'm using this on my new website/forum, I first set it up to email me when spambots visit and get blocked and I've had sooo many come through so this does work and is helpful.)
 
You should not use this code on a live site. You should not use the stopforumspam.com service to check every connection to your site. You should only check actions such as registrations. If you want to use the stopforumspam.com to block users from all of your site, you should use one of the downloads on offer on the downloads page and check every users IP against a local file of IP's.
 
Back
Top Bottom