Home arrow PHP arrow Page 2 - Using Recaptcha with AJAX in PHP

Form design, planning and implementation - PHP

With bots getting intelligent enough to read easy versions of captcha, it's time to make your site a little trickier if you want to avoid spam. This article will show you how to set up a PHP web form with AJAX that uses Recaptcha, a more difficult protocol for bots to decipher.

TABLE OF CONTENTS:
  1. Using Recaptcha with AJAX in PHP
  2. Form design, planning and implementation
  3. PHP web form scripting
  4. PHP validation script: ajaxvalidate.php
By: Codex-M
Rating: starstarstarstarstar / 4
January 28, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
 

In a PHP AJAX environment, we need JavaScript files that will work along with the application. In this tutorial, we will use the prototypeAJAXframework. All in all, we need to have the following files:

  • prototype.js: This is the default JavaScript framework needed forAJAX. A discussion of it is out of the scope of this article; you can refer to their website for details.
  • PHP Web form (index.php): This is the index.php file which will serve as an HTML form input for your users. In this form, you will need to integrate the prototype.js framework forAJAXas well as the Recaptcha.
  • Recaptcha library (recaptchalib.php): This is the PHP library file needed for recaptcha to work and communicate with their server. For a detailed discussion, refer to the Recaptcha developer website.
  • PHP validation script (ajaxvalidate.php): This is the actual PHP script that will do the actual PHP validation work.

All of these files are kept inside the same folder named "ajaxrecaptcha" so that it can be easily implemented with any server platform that is in compliance with the requirements. If you want to test this application inside an XAMPP local host, then the form URL will be: http://localhost/ajaxrecaptcha/ , or in a domain such as http://www.php-developer.org/ , the form URL accessible by the public will be located at http://www.php-developer.org/ajaxrecaptcha/ .

All naming convention of URLs use a relative URL structure for ease and flexibility of implementation on the part of the developer and the user.

If you want to implement this in your own website, aside from complying with the requirements stated earlier, you need to have your own folder name (for example, revising "ajaxrecaptcha" to "contact-me"). The folder naming in the script should also be revised, i.e. all references made to ajaxrecaptcha will be changed to "contact-me." The rest of the structure and filenames stay the same.

Of course, you will be revising the field names to suit your own application (maybe for a guestbook, inquiry form, contact form, etc.).



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: