Location: PHPKode > projects > BotDetect CAPTCHA > BotDetect-PHP-CAPTCHA-Component-vAlpha1-Build201202051720/WebApp/PhpBasicCaptchaSample/index.php
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>BotDetect PHP CAPTCHA Basic Sample</title>
  <link type="text/css" rel="Stylesheet" href="StyleSheet.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <?php require("BotDetect.php"); ?>
</head>
<body>
  <form method="post" action="" id="form1">

    <h1>BotDetect PHP CAPTCHA Basic Sample</h1>
    
    <fieldset>
      <legend>PHP CAPTCHA validation</legend>
      <label for="CaptchaCode">Retype the characters from the picture:</label>
      
      <?php // Adding BotDetect Captcha to the page 
        $SampleCaptcha = new Captcha("SampleCaptcha");
        $SampleCaptcha->UserInputID = "CaptchaCode";
        echo $SampleCaptcha->Html(); 
      ?>
      
      <div class="validationDiv">
        <input name="CaptchaCode" type="text" id="CaptchaCode" />
        <input type="submit" name="ValidateCaptchaButton" value="Validate" id="ValidateCaptchaButton" />
        
        <?php // when the form is submitted
          if ($_POST) { 
            // validate the Captcha to check we're not dealing with a bot
            $isHuman = $SampleCaptcha->Validate();
            
            if (!$isHuman) {
              // Captcha validation failed, show error message
              echo "<span class=\"incorrect\">Incorrect code</span>";
            } else {
              // Captcha validation passed, perform protected action
              echo "<span class=\"correct\">Correct code</span>";
            } 
          }
        ?>
      </div>
     
    </fieldset>
    
    <div id="notes">
			<div class="note">
				<h3>Description</h3>
				<p>This sample project shows the most basic source code required to protect an PHP form with BotDetect CAPTCHA and validate the user input.</p> 
				<p>It can be used as a starting point when you are first learning how to use BotDetect.</p>
			</div>
			<div class="note warning">
				<h3>Please Note</h3>
				<p>BotDetect PHP Captcha Library Alpha is a work in progress, and we need you to guide our efforts towards a polished product. Please <a href="http://captcha.biz/contact.html?topic=php">let us know</a> if you encounter any bugs, implementation issues, or a usage scenario you would like to discuss.</p>
    <p>The PHP library does not yet support the full feature set of the other BotDetect 3.0 Captcha products (ASP.NET and ASP Classic). Captcha localization and Captcha sounds are not implemented yet, but are coming soon.</p>
			</div>
    </div>
  </form>
</body>
</html>
Return current item: BotDetect CAPTCHA