SPAM Protection Using PHP and jQuery
April 2009 · 12 CommentsThe most common solution to keep 'machines/automated spammers' from abusing PHP forms is to use a CAPTCHA. This works, for the most part, but is very inconvenient & usually unsightly for the visitor, discouraging them from actually using the form for its intended purpose.
The solution we've come up with is much simpler than other proposed solutions we've run across. We hope you find it helpful.
Here's how it works: (view demo · source · download)
- Give your required form field a specific class
- After a visitor enters information in the text field, a call is made to the PHP script, using jQuery
- The PHP script sets a session, confirming that the visitor is actually a real person since they must have clicked on one of the form fields.
- Since the session is set, the visitor is allowed to send the form.
The only downside we can think of is that the form won't work unless the visitor has Javascript enabled, but typically over 95% of visitors to your site will have Javascript enabled.
UPDATE: (4/10) - Looks like someone else had a similar idea first: http://15daysofjquery.com/examples/contact-forms
Categories
· Mobile (1) · Projects (60) · Tutorials (14) · PHP (14) · jQuery (5) · MySQL (4)
View by date
· View All · March 2013 · February 2013 · October 2012 · September 2012 · August 2012 · July 2012 · May 2012 · March 2012 · February 2012 · January 2012 · December 2011 · November 2011 · October 2011 · September 2011 · July 2011 · June 2011 · May 2011 · April 2011 · March 2011 · February 2011 · January 2011 · December 2010 · November 2010 · October 2010 · September 2010 · July 2010 · May 2010 · April 2010 · February 2010 · January 2010 · November 2009 · August 2009 · July 2009