Drupal Comment Spam

Drupal Comment Spam

For the last few months, I've been suffering under the weight of spam awaiting 'approval' from me in the comment moderation queue.

On Saturday, I finally hacked the comment.module file to make Drupal reject spam which matched the following :

  • Author and Subject were the same - strangely a lot of spam seems to be in the format where the author and subject fields are set to the same value.
  • Body contains more than a set number of URLs - this is quite a harsh restriction I guess, but very few valid comments contain URLs anyway. I did originally have it blocking any URLS, but have since changed it to only allowing a certain number.

Spam will still have to pass through moderation from Kat or I, but so far it does seem to have stopped any crap from being posted.

The Changes

I edited comment.module and within the comment_validate function, I added the following :

  if(preg_match_all('/(http|\[url)/', $edit['comment'], $matches)) {
      if(sizeof($matches[0])>4) {
          form_set_error('comment', t("Comment contains too many URLs. (Spam protection)"));
      }
  }
  if($edit['subject'] == $edit['name']) {
      form_set_error('subject', t('Subject and author need to be different (Spam protection)'));
  }

I quite like the form_set_error function; and have been using something similar at work.

Technorati Tags:

Comments

drupal 5.1

After upgrading to Drupal 5.1 I came across the Drupal Captcha Riddler plugin, which does exactly what I had, but without any patching.

See http://drupal.org/project/riddler

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
We don't take kindly to automated nonsensible adverts around here.