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.

  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



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
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates


Dev Shed Tutorial Topics: