You are not logged in.
- Topics: Active | Unanswered
Pages: 1
#1 2008-09-10 7:01 pm
- SyKoHPaTh
- Member
- Registered: 2008-09-10
- Posts: 1
PHP form code that prevents spambots
I found this idea "somewhere", but can't remember the source. Anyway, this code follows a very simple idea - put a "visibility:hidden" input field in your html, and then in the submission PHP check to see if that field has any value.
HTML:
<input name="name" style="visibility:hidden;">
PHP:
//field should be empty - the only way it could be filled in is by a bot, since it's invisible to users.
if($_POST['name']>""){
print "That's not allowed!";
}
It's possible to even set a value in the input field, and check to see if that field still has the value set, <input name="name" style="visibility:hidden;" value="something">, where the php check is: if($_POST['name']=="something) { [passed check]; }
I hope this helps someone, as this little trick has helped me ALOT in my work!
Offline
#2 2008-09-19 9:56 pm
- andypatmore
- Member
- From: Suffolk, UK
- Registered: 2008-08-24
- Posts: 18
- Website
Re: PHP form code that prevents spambots
I have seen this too but have also read about the pitfalls of using this system, especially where some "bots" have limited AI and can actually check to see if a form field is actually visible (ie. not hidden or floated 5000px to the right!)
Every little helps as they say!
Something else that may be of use is http://www.spampoison.com/. I haven't used it myself, but it is fun to think that you are doing your bit to foil a few bots!
Coming back to the AI in bots, some of the problem lays in the form field names. Bots will "look" for username, email, age, city, etc and complete forms correctly and automatically! I have actually seen one in action recently and it was quite scary! The only way round this is to use non-standard or even random field names sausage, cupcake, anotherbeer, h6hd93873, etc Oh, I have seen it tried, but the bot I watched in action got round u53rn4m3, nameuser and usernaem Obviously this is a problem for Forum/CMS script developers and not users, but an understanding of the problem is always useful.
Offline
Pages: 1