create captcha using php jquery and ajax example

42

Captcha code in a form is used for ensuring that the form is submitted with manual intervention without any tools or programs. In the previous tutorial, we have seen how to add captcha in PHP.

In this tutorial, we are using jQuery AJAX for getting captcha image from PHP. Using jQuery we can also refresh the captcha code by resending AJAX call to generate new captcha image.

Contact Form with Captcha

This code is for displaying contact form with refreshable captcha image.

We have same validation script as we have seen in jQuery contact form tutorial. So, the following code shows only the validation of the captcha field.

jQuery Captcha Refresh

This simple jQuery script will refresh PHP captcha code and recreate the image with the new code. This new image will be set as captcha image source.

PHP Captcha Image Creation

In PHP we are using PHP rand() to generate a random number. This random number will be encrypted by using md5() and cropped into 6 character captcha code. Then this code will be added to PHP session and as a source of captcha image by using PHP GD functions.

 

Leave A Reply

Your email address will not be published.