Link to home
Start Free TrialLog in
Avatar of alivemedia
alivemedia

asked on

stop bots from submitting forms

some bots have found my site which accepts a form from users for posting of classified ads.  Now I get at least 1 every five minutes from adamn bot.

How do I prevent this?
Avatar of Rytmis
Rytmis

For a site of mine we implemented a fairly simple solution.

We had two fields, name and message, so we introduced two new fields with mangled names, and use those instead. We use CSS to hide the old fields, and just in case CSS is disabled, both hidden fields have labels saying "please do not fill this field" next to them.

Every time a comment is posted, we check if either of the hidden fields have text in them. If they do, we mark the message as spam. Messages marked as spam are not displayed.

Every now and then I manually clean up the accumulated spam messages, but the end users don't see any of it any more.
Avatar of alivemedia

ASKER

I guess this assumes that the bots don't use css or have it disabled?
There are two solutions.

1. Use image with text in it for verification similar to what yahoo and hotmail does while signing up.  
http://www.finalwebsites.com/snippets.php?id=39
or
http://www.phpclasses.org/browse/package/1569.html

2. Usually, these bots leave a message that has a certain pattern to it.  Such as they will always have <a href="somelink">somelink</a>[url]somelink[/url]

If so, you can update the script that processes the form submission to look for this pattern using some regular expression.  If it matches that regular expression, you can mark it as spam.  However, this is risky as you may get a false positive from time to time.  

The best solution is of course to use the CAPTCHA logic where user has to provide text that matches a randomly generated image as show in above link.  This method is used by big sites that have a great deal of hits from all kinds of bots.

Well basically the bot can't tell *why* the field is hidden (lots of ajaxy things keep stuff hidden via CSS rules). Anyways I'm not saying this is the be-all end-all solution, but 100% of the spam we've been getting has been caught in it.

I'm thinking that if this filtering stops being effective at some point, I'll probably start changing the field name on every page load. I'm pretty sure that the bots don't load the page as often as they post to it.
If you're sure that the bot is not loading the page before submitting, add a session variable to the form page. If this session variable is not set when the form processor script is reached, send a thank you message as though you're happy with their rubbish, but silently discard the submission. No legitimate user should be posting to your processor script without using your form first.
ASKER CERTIFIED SOLUTION
Avatar of _delas
_delas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As a curiosity: during the last two weeks our simplistic filtering has stop some ~400 spam comments (and amazingly, not a single one has yet come through). YMMV though.