...

View Full Version : Help me block those pesky spammers - Method being tested - Ran into a bug



smiffy
10-20-2005, 12:31 AM
First of all I'd like to say hello to all... :) [wave]

I'm a moderate X/HTML and CSS programmer but I have little skill in the art of javascript and other languages etc... but I need help stopping spammers playing in my guestbook (Advanced Guestbook 2.3.3), so I thought I'd ask you guys for some guideance.

The majority of visitors to my site go directly to my guestbook 'addentry.php' so I thought... if I add some code in my .htaccess file to deny access to addentry.php if referer is null I could stop about 95% - 100% of these spammers.


This is the sort of thing I'm looking to implement (BTW: This is not real code but an example of what im trying to acheive... if possible!!)

IF PAGE_REQUEST = mydomain/guestbook/addentry.php
THEN IF REFERER_URL = NULL
DO REDIRECT = /error/403_forbidden.shtml


I'm sure this would be valuable in keeping out pesky spammers, and less time consuming than using the 'deny from xxx.xxx.xxx.xxx'. Also, modifying my guestbook so that entries get approved first is a last resort fo me, I would rather have less maintenance.

Anybody have any ideas?..

mark87
10-20-2005, 01:24 AM
Sorry can't help you with the PHP, but I also use Advanced Guestbook - and even though I've read about the problem of spammers with it, I haven't had any (touch wood).

How do they actually find your page?

You could rename the addentry.php file - and all references to it - if that's what they look for, and also rename the link at the bottom saying 'Advanced Guestbook...'. With AG you can also set the maximum length of message/characters.

smiffy
10-20-2005, 01:54 AM
Hi mark87


How do they actually find your page?For about 2 weeks my log files have been reporting a lot of hits (about 20 hits a day) to my addentry.php but had no referer, except one, that was refered by a google search for 'addentry.php'.

I'm baffled how they found my guestbook but nothing was being posted, so i wasn't too concerned up until a couple of days ago when posts started. They come in the form of 'great site', 'nice layout' etc... how would they know? they only visited the addentry page!!

I thought about renaming the page but I've read of others doing the same but the problem returned sometime later... You'd think they'd have better things to do.

I'm sure there is a way to deny a certain page as the entry point to a website but I don't have the knowledge... just the idea. Thanks for your reply though and keep touching wood :thumbsup:

Al_90
10-20-2005, 03:41 AM
if you know there ip addresses, then ban them from all pages

vinyl-junkie
10-20-2005, 03:46 AM
I did a bit of Googling on your behalf and found a great solution in another forum:


The solution is to modify a bit your guestbook so that the bots will not be able to automatically post in it. Just add something unique in the form (a hidden input field) where a guestbook entry is made. Then modify the source code of the guestbook to check if the hidden field is present before adding the entry. It shoud be very simple to implement.

I've seen something similar to this. I didn't try looking at the code for it but I think what they did was setup a javascript alert button which had to be clicked before the desired action would take place (which of course in your case, is to post to your guestbook).

smiffy
10-20-2005, 04:30 AM
if you know there ip addresses, then ban them from all pagesI have already started banning IP addresses that are leaving posts but there are hundred+ others that are directly hitting my addentry file that haven't left a message... yet! It just seems impracticable to have a list to include them all in my .htaccess file.

edit: I have had 249 unique IP visitors/spammers to this page since 1st Oct '05 :eek:

vinyl_junkie:
Thanks for your googling... do you have a link to the information you mentioned?

vinyl-junkie
10-20-2005, 04:45 AM
vinyl_junkie:
Thanks for your googling... do you have a link to the information you mentioned?
Sorry, I don't. The post in that other forum was really the only difference in that thread to what has already been discussed here. I have very limited javascript skills myself, so I'm afraid I wouldn't be much help actually setting up what I suggested.

What you might do though is post a question in the javascript forum and ask for some help putting the code together.

smiffy
10-20-2005, 02:52 PM
What you might do though is post a question in the javascript forum and ask for some help putting the code together.I'm sure it's not allowed... Posting Guidelines (1).

Unless a moderator could move this post for me.

vinyl-junkie
10-20-2005, 03:09 PM
You might want to contact a moderator for clarification, but I don't see this as cross-posting, as long as you don't copy/paste your original question into the javascript forum. This is a related question, in my opinion, and more to do with javascript than general web building.

The question that you should ask is "How do I tack on a javascript alert (or something similar) to my guestbook to stop at least some of the spam?" You can word that however you want. You'd probably want to give a link to this thread so that the whole solution isn't rehashed.

If a moderator deems the above as cross-posting, I'd be interested in their reasoning.

smiffy
10-20-2005, 04:08 PM
Before I post in another section I took your advice and I've just PM'ed a Moderator... Just to be safe.

mlseim
10-20-2005, 10:58 PM
I'm guessing the spammers are using some automated software to hammer your guestbook.

Try this:

Using Javascript on your main page, set a cookie.

Then,

When the visitor goes to another page to write in your guestbook,
use Javascript to check for that cookie.

Note: Cookies can't be set and read on the same page without a
page refresh, thus the mention of having it set on the main page, and
the visitor going to another page to write in your guestbook.

------------------

I would guess that the spammers would be blocked because the cookies are a function of the browser, and they aren't using a browser.

I've never tried it, but it's an idea that might work.

The only "bad thing" would be if someone has their cookies turned off.
But, most people have them enabled.

PhotoJoe47
10-20-2005, 11:16 PM
I'm far from a JS expert, I just know enough to be dangerous.

But with the website that I'm building I use frames. Everypage that I have written, (but the opening mainpage) has a bit of JS that keeps anyone from accessing that page directly.



<script>
//By JavaScript Kit (http://javascriptkit.com)
//Over 400+ free scripts here!

//if not in frames
if (parent.frames.length==0)
//CHANGE "index.htm" to the URL of your main frame page
window.location.replace("index.htm")
</script>


Now if you don't like to use frames maybe you are someone with better knowledge can change this so it can read a session cookie that would be created from your home page. I think someone above suggested that.

PhotoJoe

felgall
10-20-2005, 11:58 PM
Chances are that the program the spammers are using to hit the guestbook doesn't process the Javascript and therefore can access the page directly. Whatever javascript solution you implement will be completely bypassed by their program. You need to implement a server side solution to block the spammers.

The two most common solutions I have seen implemented are to display a graphic that contains some characters that must be entered into one of the fields in order to post (and the spammers program can't read the graphic content) and to block multiple posts from the same IP address within a given time period (eg. 15 minutes).

mlseim
10-21-2005, 01:44 AM
OK,

So let's take the cookie idea a step farther.

If you set the cookie using Javascripting and then
look for the cookie in the PHP script, that would solve
the spammer problem, since the cookie would not be
set to begin with (they disable Javascripting).

That might work.

smiffy
10-21-2005, 03:18 AM
I'm guessing the spammers are using some automated software to hammer your guestbook.You are right they dont look at any of my website except the addentry.php... I woul

smiffy
10-21-2005, 03:30 AM
Chances are that the program the spammers are using to hit the guestbook doesn't process the Javascript and therefore can access the page directly. Whatever javascript solution you implement will be completely bypassed by their program. You need to implement a server side solution to block the spammers.

this is exactly why i want to write a simple code in my .htaccess to stop unknown referers.

I may have undestood you wrong but I must stick with the method I feel has to work!!

smiffy
10-21-2005, 03:41 PM
I've just added some code to my guestbook that prevents a user from accessing my addentry.php directly, a user has to access this page from the index.php like any normal person would. If somebody tries they get redirected to my 403_forbidden.shtml.

This is the code I used:

In guestbook/index.php
<?php
session_start();
$_SESSION['valid'] = "yes";

And in guestbook/addentry.php
<?php
session_start();
if ($_SESSION['valid'] != "yes") { header("Location: http://mydomain/error/403_forbidden.shtml"); }


All I've got to do now is sit and wait to see if it works against those pesky spammers.

vinyl-junkie
10-22-2005, 08:41 AM
Would you like for anyone from the forums to test out your code? If so, and if you'd rather not post the link publicly, feel free to PM me with the link. I'd be happy to try it out for you. :)

smiffy
10-22-2005, 03:18 PM
24 hrs and counting... So far I have blocked 18 out of 18 :D

Im now keeping my fingers crossed that I have a simple but effective method of keeping pesky spammers out. I shall be monitoring for a about a week before I decide I have a cure.


Would you like for anyone from the forums to test out your code? If so, and if you'd rather not post the link publicly, feel free to PM me with the link. I'd be happy to try it out for you. :)You have PM :thumbsup:

vinyl-junkie
10-22-2005, 05:57 PM
For the record, I tried out smiffy's new anti-spam measures, and it seems to work quite well. Great job! :thumbsup:

Thanks for sending me the link and letting have a go at it. :)

smiffy
10-25-2005, 08:58 PM
Well so far I've blocked 40 out of 40 pests... but... I've found a bug in my code :(

It has somehow stopped the preview function working properly. I've posted here (http://www.codingforums.com/showpost.php?p=368246&postcount=1) in the PHP section hoping for some guideance.

pj27559
06-11-2007, 10:09 PM
I had the same problem with advanced guestbook a few years ago, it's a nice guestbook, but lacks security features.

I stumbled across a guy who has rewritten it with new security features for those who don't want to code things for themselves


http://www.carbonize.co.uk/Lazarus/index.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum