Simple Anti-Spam Redux

Simple anti-spam mod for PunBB/FluxBB 1.2, writ­ten by Matt Fretwell (MattF) in sirena’s SAS mod topic on punbb.org. Pre­par­ing for the last days of 1.2, I decided to pol­ish it a bit. I updated the code to the last bug­fixes provided by Matt, intro­duced lan­guage file sup­port to some extent.

So, this is simple anti-spam mod, based on tex­tual captcha (arith­metic or tex­tual ques­tions). It is pretty effect­ive, on low-volume for­ums at least. Tested on 1.2.15, 1.2.18‒1.2.20.

Plans

Sup­port for guest post­ing (post.php), more lan­guage files (help appre­ci­ated, e-mail to post­mas­ter [at] theug [dot] pp [dot] ru), pos­sibly inclu­sion of admin-panel. Then, once the 3rd beta of FluxBB is out, I’ll start on the extension.

Install­a­tion

1. Cre­ate ./include/user/sas.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
 
session_start();
if (!isset($_SESSION['answer']) || $_SESSION['answer'] == '')
{
	$number = rand(1, 5); // Alter the second number to match the number of questions.
 
// Questions array
 
	$questions = array(
 
	'q1' => '4 + 5 =',
	'q2' => '12 - 6 =',
	'q3' => '3 + 2 =',
	'q4' => '8 - 1 =',
	'q5' => '8 - 4 ='
 
	);
 
// Hints array
 
	$hints = array(
 
	'h1' => 'One less than ten',
	'h2' => 'One more than five',
	'h3' => 'Just under six',
	'h4' => 'That many days of the week',
	'h5' => 'One more than three'
 
	);
 
// Answers array
 
	$answers = array(
 
	'a1' => '9',
	'a2' => '6',
	'a3' => '5',
	'a4' => '7',
	'a5' => '4'
 
	);
 
	$_SESSION['hint'] = $hints['h'.$number];
	$_SESSION['answer'] = $answers['a'.$number];
	$_SESSION['question'] = $questions['q'.$number];
 
}
 
?>

2. For regis­tra­tion captcha, here’s ./register.php edit steps:

Find near the top:

if ($pun_config['o_regs_allow'] == '0')
{
		require_once PUN_ROOT.'header.php';
		message($lang_register['No new regs']);
}

Add after:

// Load the Simple Anti-spam script and language files
require_once PUN_ROOT.'include/user/sas.php';
require_once PUN_ROOT.'lang/'.$pun_user['language'].'/sas.php';

Find:

		$language = $pun_config['o_default_lang'];

Add after:

	if (isset ($_POST['spamcode']) && $_POST['spamcode'] != '' && strtolower($_POST['spamcode']) == strtolower($_SESSION['answer']))
	{
		session_unset();
		session_destroy();
	}
	else
	{
		session_unset();
		session_destroy();
		message($lang_sas['Spamcode failed']);
	}

Then insert form por­tion in the respect­ive part of the code:

<div class="inform">
				<fieldset>
					<legend><?php echo $lang_sas['Anti-spam legend'] ?></legend>
<div class="infldset">
						<label>
						<b><?php echo $lang_sas['Question'] ?></b> <?php echo $_SESSION['question']; ?>
<input type="text" name="spamcode" size="10" maxlength="10"/><br/>
						<b><?php echo $lang_sas['Hint'] ?></b> <?php echo $_SESSION['hint']; ?>
						<br/></label>
					</div>
 
				</fieldset>
			</div>

3. Lan­guage file (cre­ate ./lang/English/sas.php):

1
2
3
4
5
6
7
8
9
10
11
<?php
 
// Language definitions used in Simple Anti-Spam Redux modification
$lang_sas = array(
 
	'Anti-spam legend'		=>	'Spambot prevention question',
	'Question'			=>	'Question:',
	'Hint'				=>	'Hint:',
	'Spamcode failed'		=>	'The anti-spambot answer you supplied was incorrect. Please try again.'
 
);

5 Responses to “Simple Anti-Spam Redux”


Leave a Reply




Bad Behavior has blocked 1001 access attempts in the last 7 days.