Support » Plugins » Quick Anti-Comment Spam Hack

  • First, the disclaimer: This hack is just that, a hack. I don’t claim that it will work, nor do I claim that it won’t. However, I can say that I currently is working for me. Also, I am aware of the fact that this is merely a short term solution. In fact publishing this method for blocking comment spam, will probably result in it becoming ineffective within a couple days. But, that could mean that we might get a couple days of rest from the comment spammers.
    Here’s what I did. After checking my server logs for several weeks (I don’t get many real comments), I noticed that <b>none</b> of the spam comments had a valid referer set, while all of the valid comments did. I’m sure many of you know where I’m going now. I opened up b2comments.post.php in my favourite text editor, scrolled down to where I saw:
    <pre>
    if ('closed' == $commentstatus)
    die('Sorry, comments are closed for this item.');
    </pre>
    I added a line below that test, and started typing:
    <pre>
    if ( !preg_match( "/type.your.domain.here/i", $GLOBALS["HTTP_REFERER"] ) ) {
    die('Sorry, your comments are blocked for spam infringement.');
    }
    </pre>
    Then I saved the file. You will want to enter your domain into the space where I typed <b>type.your.domain.here<b>, but that’s all there is to it. Granted I don’t know how well this will work for you, but it cut my little site from 2 comment spams a day, down to none since the install.
    Good luck!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks for this quick fix – I’ll try it out since I just noticed that I have been receiving comment spam for the first time!
    I haven’t checked in here yet, and I’m sure it exists, but is there something that will automatically close posts to comments after a set time?

    One more thing… the $GLOBALS didn’t quite work for me, I used
    $HTTP_SERVER_VARS[“HTTP_REFERER”] instead. Not sure if one is more appropriate or not, though.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Quick Anti-Comment Spam Hack’ is closed to new replies.