views:

141

answers:

2

I'm implementing a contact form for a website, and I'd like to avoid using a captcha because I believe it has a negative effect on user experience.

Instead, I've decided to trial detecting the number of URLs that have been submitted with the message.

I am retrieving the message as a string from the $_POST submission. I know inbuilt PHP functions such as stristr() can give me confirmation that a substring exists within the message but what I'd like is the count.

Also, in terms of spam detection, would a match on something like "</a>" be appropriate?

Cheers.

+3  A: 

substr_count($text, "http") http://www.php.net/manual/en/function.substr-count.php

Note that isn't sufficient, but neither is allowing users to enter unfiltered data into your form fields that gets rendered as html.

I shouldn't be able to put javascript in there either due to Cross Site Scripting http://www.owasp.org/index.php/Top%5F10%5F2007-Cross%5FSite%5FScripting

I'd recommend using http://htmlpurifier.org/ to remove any malicious code.

Finally for spam filtering I'd recommend http://akismet.com/

Good luck.

Stephen lacy
html, javascript and SQL injection handling is fine. I'm not even rendering anything on the page, I just want to automatically disallow as much spam as possible. Everyone always assumes that because I didn't specifically mention HTML injection handling that I must have neglected to do it even though it has nothing to do with my original question.
Evernoob
Sorry, however it's still worth risking annoying you if there is a chance it hasn't occured to you. Have a look at akismet, that handles spam much better than url counting. It's what is used in practically every wordpress.
Stephen lacy
Also in case you missed it I directly answered your question with the first part of my post. Allowing you to ignore the rest.
Stephen lacy
A: 

if this is a contact form, there is no need to accept html. just encode the whole content and limit the number of posts from the same ip or limit the time between messages.

yes you could restrict the number of urls, but i don't think this is effective

w35l3y
It will be effective in reducing the spam I already get through the contact form, which are all infested with URLs. Most of the bots, though clearly the same are able to switch IP addresses, but the time between messages idea is good.
Evernoob