Simple anti-spam mod for PunBB/FluxBB 1.2, written by Matt Fretwell (MattF) in sirena’s SAS mod topic on punbb.org. Preparing for the last days of 1.2, I decided to polish it a bit. I updated the code to the last bugfixes provided by Matt, introduced language file support to some extent.
So, this is simple anti-spam mod, based on textual captcha (arithmetic or textual questions). It is pretty effective, on low-volume forums at least. Tested on 1.2.15, 1.2.18‒1.2.20.
Plans
Support for guest posting (post.php), more language files (help appreciated, e-mail to postmaster [at] theug [dot] pp [dot] ru), possibly inclusion of admin-panel. Then, once the 3rd beta of FluxBB is out, I’ll start on the extension.
Installation
1. Create ./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 registration 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 portion in the respective 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. Language file (create ./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.' ); |
message("$spamcode_failed");modified
Thanks for noticing the error. I had it properly in my live code, but I didn’t update the code in the text file draft, from which I copied here.
Looks good! I guess I’ll see how effective it is in a day or so.
hi, what about your plans for guest posting (post.php)?
thanks
Plans are the same, however, meself I am the “copy-paste coder”, so I don’t know much about programming beyond basics, nevermind intricasies of PHP or specifics of FluxBB. I posted several questions on different Flux/Pun forums, but had no coherent reply yet.