Please login or register.

Login with username, password and session length

Author Topic: [MOD] Additional Anti-Spam Measures for forms for V1.5.42  (Read 2697 times)

bakercad

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 105
  • Posts: 1670
    • http://exit20.com
[MOD] Additional Anti-Spam Measures for forms for V1.5.42
« on: June 28, 2007, 08:02:31 PM »

This MOD for sNews 1.6

This creates an extra "hidden" input field into the mathCaptcha function.  It's purpose is to assist in eliminating spam from being submitted through forms.

How it works
An addition input field called "important" is added to any form using mathCaptcha.  Using CSS this field is hidden.  So your site viewers can't see it, thus they can't input a value.  However, when a spam bot sees the field, it will assume that it needs to be filled in and will enter a value.

The additional code will check to make sure the value is empty, if it's not, it returns an error and the form is not submitted.

STEP 1 - BACK IT UP!

STEP 2 - in snews.php edit the mathCaptcha function as so:
ADD the blue

Quote
// MATH CAPTCHA
function mathCaptcha() {
    $x = rand(1, 9);
    $y = rand(1, 9);
    $math = '<p><label for="c">* '.l('math_captcha').':</label>
';
    $math .= $x.' + '.$y.' = ';
    $math .= '<input type="text" name="calc" id="c" style="width: 30px;" /></p><p>';
   // Original code : $math .= html_input('hidden', 'sum', 'sum', $x + $y, '', '', '', '', '', '', '', '', '', '', '').'</p>';
   $xplusy = $x + $y;
    $math .= '<input type="text" class="important" name="important" id="important" />'; // NEW LINE
   $math .= "<input type=\"hidden\" name=\"sum\" id=\"sum\" value=\"$xplusy\" /></p>";
   
    return $math;
}
STEP 3 - snews.php

FIND all instances of this (should be 3)
Quote
//$calc = $inputCalc === $sum ? $inputCalc : null;
CHANGE TO THIS
Quote
//$calc = $inputCalc === $sum ? $inputCalc : null;
$calc = $inputCalc === $sum && empty($_POST['important']) ? $inputCalc : null;
STEP 4 - then added this to the style.css file (as in the article you posted)
Quote
.important {
width:5px;
visibility:hidden;
}
« Last Edit: April 11, 2008, 02:45:23 PM by bakercad »
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD] Additional Anti-Spam Measures for forms for V1.5.42
« Reply #1 on: June 29, 2007, 09:11:17 AM »

Ahhh, goodie, darling... Will try it out as soon as I have time...Just browsing forum one last time before soccer... ;)
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs