Blacklisting words

0 views
Skip to first unread message

Hinch

unread,
May 23, 2009, 10:12:49 AM5/23/09
to Pixie
Over the last week one post on my site attracted over 350 spam
comments on the same subject. Every single post was offering 'cialis'.

Using the bad behaviour functions is there a way of blacklisting the
word 'cialis' from comment posts?

Scott

unread,
May 24, 2009, 1:26:20 PM5/24/09
to Pixie
Hi Hinch
As far as I know the bad behaviour script only has a blacklist for IP
addresses and not for keywords. Did all the spam comments originate
from one IP address? You can find out more about BB here:

http://www.bad-behavior.ioerror.us/documentation/

If you are looking to block a certain keyword the file you want to
poke around with is: admin/modules/dynamic.php - somewhere around line
83. You could run a check along the lines of:

if (strpos($comment, "BANNED WORD") !== false) { $error .= "Your
comment contains a nasty word. Sorry. |"; $scream[] = "comment"; }


Scott

Hinch

unread,
May 30, 2009, 7:01:31 PM5/30/09
to Pixie
Hi Scott,

The comments came from different sources, really odd - as soon as I
deleted them (directly in the DB, I might add a multiple delete option
to my dynamic.php just in case of future problems) I received about 10
more while just messing around with my CSS over the course of half an
hour or so.

I've added a simple check using strstr(); and an array of bad words
which returns the error message 'sod off' =)

Hinch

unread,
May 30, 2009, 7:13:49 PM5/30/09
to Pixie
Forgot to add, this is the code to check, added to line 84 of admin/
modules/dynamic.php

// Bad word check
$badwords = array( 'viagra', 'cialis' );
function badword_check($haystack, $needle) {
foreach ($needle as $word) {
if ( strstr( $haystack, $word ) ) return true;
}
}
if ( badword_check($scomment, $badwords) ) $error .= 'Sod off';

Scott

unread,
Jun 6, 2009, 9:19:13 AM6/6/09
to Pixie
Hi Hinch
Thanks for posting back the code, and glad that you found a fix. How
have the spam levels been? The pixie site got hit by quite a great
deal of spam yesterday, I ended up blocking a couple of IP addresses.

A sensible future feature of Pixie would be both a keyword and IP
address check on comments before saving them (and an admin page to
work add the blacklisted words and IPs). I think your code forms a
basis for this.

Thanks again

Scott

Hinch

unread,
Jun 7, 2009, 3:31:35 PM6/7/09
to Pixie
Unfortunately not much better, now it's stuff about periodic tables
and weight watchers!

I think an IP check and save would be very wise!

Hinch

unread,
Jun 8, 2009, 9:07:17 AM6/8/09
to Pixie
I've added a very, very quick code for a session and message limit to
the top of the main index.php file:

// Visitor session start
session_start();
if (!isset($_SESSION['visitor'])) {

session_register('visitor');
session_register('spam_comments');

$_SESSION['visitor'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['spam_comments'] = 0;
}

// If post, add to count
if ($_POST['form_action'] == 'post_comment') {
$comments = $_SESSION['spam_comments'];
$_SESSION['spam_comments'] = $comments + 1;
}

// Too many comments
if ($_SESSION['spam_comments'] >= 5) $spamlimit = true;
else $spamlimit = false;

===========================================

It's crude but it works. The variable $spamlimit is used in
dynamic.php and decides whether to show the comment form or not.

Scott

unread,
Jun 10, 2009, 4:11:17 PM6/10/09
to Pixie
Hi Hinch
Thanks for the code, its a nice little trick to stop over posting of
comments and will be very useful for people suffering from repeat
spam. I can see something similar to this working its way into Pixie.

Cheers

Scott
Reply all
Reply to author
Forward
0 new messages