Referer Spam Blocker for b2evolution

Yet another accomplishment in my ongoing quest to combat referrer spam.

This script automatically updates your .htaccess file to block hits from any referer in your blacklist.

I saved this script in my admin folder, and set up a cronjob to run it every 4 hours, along with my antispam update script and recheck script.

In order to gracefully handle possible false positives, add this to error.php:

[The requested file /home/yaohytmw/isaacschlueter.com/download/b2evo/error.php could not be found]

That allows someone from a bad referer to click through to the requested page. Of course, if it’s a referer-spam bot, then it will send its bogus referer header again, and get stuck on the same page over and over again. But, valid people can get through to what they want.

There isn’t much more that I can add to the script itself, so take a look and let me know what you think.

10 Responses to “Referer Spam Blocker for b2evolution”

  1. On June 26th, 2005 at 15:52:38, ferrethouse Said:

    If this works it is friggin brilliant. I’m getting hit with about 20 gigs of referer spam bandwidth per month and I can’t afford it. I’ve even considered moving to WordPress. I hope this helps!! Thanks.

    Now I just need to figure out how to set this up as a cron job (I’m not a php/perl/unix person).

  2. On June 27th, 2005 at 09:52:48, Isaac Schlueter Said:

    For some reason, whenever the cron job runs this script, access to my whole site is denied with a 403 error. The .htaccess file is fine, permissions are fine. Actually, I just download my .htaccess, delete it, and re-upload it, and it’s fine again. I can run the script manually 100 times without any problems, but when cron runs it, I get the 403 error.

    Very annoying. I guess I’ll just have to figure out another way to skin this cat. In the mean time, I’m just running it manually every day or so.If you have this problem, then another way that you could do this is to set up a scheduled task in Windows that runs a batch file.

    1. Create a text file, and write this in it:"C:Program FilesInternet Exploreriexplore.exe" "http://your.site.com/admin/b2antispam_genhtaccess.php"

    2. Save it as htaccess.bat

    3. Create a new scheduled task (Start > Control Panel > Scheduled Tasks) and point it at the htaccess.bat file you created.Update:
    The problem doesn’t occur if I cron a script that includes this one. Weird. I just had my antispam updater/rechecker include this at the end if it adds anything.

  3. On July 6th, 2005 at 08:48:50, Movie Reviews Said:

    I implemented this on my site yesterday and it’s working flawlessly, I’m a person that likes to tail my access_log throughout the day and I was so pissed off at the amount of constant referral spam I was seeing. After setting this up (dead easy) and telling apache not to log referer_spam I’m a happy camper.

  4. On July 26th, 2005 at 21:52:15, Daethian Said:

    I’ve hit a problem. When I try to leave a comment on my second blog… the page comes up asking you to click to bypass yada yada… but when you click it returns to my main blog and so it continues in a vicious circle.

    How do I fix this???

  5. On July 27th, 2005 at 07:46:27, Isaac Schlueter Said:

    Daethian,

    What do you have in your .htaccess file?

    That behavior would seem to indicate that the script thinks that your site is a spammer, which obviously isn’t correct.

  6. On July 27th, 2005 at 13:09:54, Daethian Said:

    Right now there should be nothing. I restored the original file last night.

    How do I tell it I’m not a spammer?

  7. On August 1st, 2005 at 11:42:14, Eric Said:

    The script works very nicely. At the end of it it chmods the htaccess file to 0600, this for some reason causes the htaccess to block everyone with 403. I changed it to 0777 and it works fine.

  8. On August 1st, 2005 at 13:06:21, Isaac Schlueter Said:

    Wow, thanks Eric.

    I had run into that problem, but only once in a while. Thanks for finding and pointing out the offensive line.

    I commented out the lines in the script, so hopefully others won’t have this problem.

  9. On February 12th, 2006 at 12:02:28, guchuj05 Said:

    “I saved this script in my admin folder, and set up a cronjob to run it every 4 hours, along with my antispam update script and recheck script.”

    What is a cronjob? And how do you set one up?
    Thanks,
    J

  10. On February 13th, 2006 at 09:59:35, Isaac Said:

    JG,

    Please see this page and read all that it has to say.

    In particular, pay attention to the sections on RTFM and STFW.

    I am happy to share information, and even help to enlighten where I can. I try not to be rude, even when annoyed. But I’m not teaching an “Intro to Web Mechanics” course.

    You’re going to have to hunt this beast on your own, Grasshopper.

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.