Simple Captcha code in Php and Javascript

In websites ,captcha is used to find if  you  are human being or machine.

In most cases captcha using  in forms like (contact form,Registration form etc…).In this tutorial  I have create a very simple captcha  code in  PHP and javascript.

captcha php

First I create a new file called contact.php .this file contains html contact form with captcha field.

In this above code I create a simple contact form with basic fields and user entered captcha  field.I show a random number using php rand function. This function used to show a random string.

Next  I need to compare user entered captcha and shown captcha both are same. if not same display error message.using javascript .below code explain it

Next add refresh button in this part I need to  use javascript for regenerate random number and put on captcha field in client side.below code done this work

Finally form contains no errors submit the form

 

facebooktwittergoogle_plusredditby feather
  • Sneha Barve

    using this captcha preventing default form action without any error… redirecting to same page. why??