PHP
  Home arrow PHP arrow Using Recaptcha with AJAX in PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
iPad news and developer info.
Ads by affinity 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Forums Sitemap 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using Recaptcha with AJAX in PHP


By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2010-01-28


    Table of Contents:
  • Using Recaptcha with AJAX in PHP
  • Form design, planning and implementation
  • PHP web form scripting
  • PHP validation script: ajaxvalidate.php

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Summary: 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.

    Using Recaptcha with AJAX in PHP
    (Page 1 of 4 )

    After a previous tutorial on PHP Ajax web forms, there were a lot of good points raised by the readers which could dramatically improve the usability and performance of any PHP AJAX web form validation. 

    Any good PHP web form should be able to accomplish the following important objectives: 

    1. The form validation should display all errors at once. The original web form discussed in the tutorial mentioned above can't currently display all errors found in the PHP server side validation. As a result, it will only display a single error at a time. This is due to the use of the die () command. For example:

    if ($countfirstname <2) {

    echo 'ERROR: You are using an invalid first name, it should contain more than one character.';

    die ();

    } 

     

    The die () command terminates the execution of the PHP script and displays the error back to the browser. 

    2. The captcha needs to be difficult. Modern bots have evolved to read easy captchas, according to Wikipedia. Fulfilling a need for a more challenging captcha like Recaptcha ( ) is important. 

    3. Users should able to easily change wrong information entered into the form without needing to press the browser's back button. This is whereAJAX-enabled web forms are useful. 

    4. Combining a PHP web form withAJAXvalidation means doing server-side validation of user inputs without the need for client validation like JavaScript (becauseAJAXitself is based in JavaScript). This eliminates the risk of spoofing common in-client validation.

    Main requirements 

    Unfortunately this type of Recaptcha AJAX in PHP will not work in all hosting accounts. It requires:

    1. That an important PHP function for communicating with Recaptcha server be enabled. An example of this function includes Fopen. Typically these are disabled in free hosting accounts for security reasons. However, if you have a paid hosting account, then you need to find out if these are enabled by checking php.ini file.

    2. A Recaptcha account for your own website. You should register it by signing up for Recaptcha for free. You need two important keys which you will get after signing up, and it is recommended that you copy these keys to a text file like notepad for your personal records. These keys are the Public Key and the Private Key. Without these important keys, your PHP web form usingAJAXand Recaptcha will not work.



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

       

    PHP ARTICLES

    - MVC and the Zend Framework
    - PHP: Rendering Web Pages Using the Composite...
    - PHP: Creating Dynamic Web Pages with the Com...
    - Secure Encrypting and Decrypting for Your PH...
    - PHP: Creating Single View Objects with the C...
    - PHP: View Object Collections and the Composi...
    - Securing Your PHP Website
    - Determine Link Relevance and Unique Class C ...
    - PHP Composite View Design Pattern: Introduci...
    - Facebook PHP API Applications: A Second Look
    - Secure PHP Programming
    - Facebook PHP API Applications: Basic Introdu...
    - SOAP Servers and Web Services
    - Using XPath, SOAP, and More with Web Services
    - Web Services: SimpleXML


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek