<?php 
/*
*we create the generel form with image src to php_captcha.php and "captcha_key" stored in session.
*when user submits the form we check for it.
*and run routine form validations for email ,name ...etc
*Author:G mahesh chari (http://www.maheshchari.com)
*/

@session_start();
$errors=array();
if(isset($_POST['Submit'])){ //if user submits the form
if($_SESSION['captcha_key']!=$_POST['captchacode'])  
//check whether stored in session value with the user submitted values
$errors[]="Invalid Captcha Code.";
if($_POST['yourname']=='')
$errors[]="Name is Required.";
//everything going fine user submitted real data and the user is real user not bot
//proces the data what we want to form data.
if(count($errors)==0){
echo "Captcha and Name is verified.";
}
}
?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Captcha test by mahesh chari</title>
</head>

<body>
<form id="example" name="example" method="post" action="">
  <table width="500" border="2">
    <tr>
      <th colspan="2">Register
	  <?/*php 
	  /* if user submits and any errors exists we display them for user. */
	  if(isset($_POST['Submit']) and count($errors)>0){
	  foreach($errors as $k=>$v){
	  echo '<br/>'.$v;
	  }	  
	  }*/?></th>
    </tr>
    <tr>
      <td>Your Name </td>
      <td><input name="yourname" type="text" id="yourname" /></td>
    </tr>
    <tr>
      <td>Captcha</td>
      <td>
	  
	  <input type="image" name="imageField" src="images/captcha.JPG" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
	  
	  <input name="captchacode" type="text" id="captchacode" /></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit" /></td>
    </tr>
  </table>
</form>
</body>
</html>-->
