Location: PHPKode > projects > BotDetect CAPTCHA > BotDetect-PHP-CAPTCHA-Component-vAlpha1-Build201202051720/WebApp/BotDetectFeaturesDemo/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 Features Demo</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 Features Demo</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";
        
        if ($_POST && isset($_POST['ApplyCaptchaSettings'])) {
          if (isset($_POST['Locale'])) {
            $SampleCaptcha->Locale = $_POST['Locale'];
          }
          if (isset($_POST['CodeLength'])) {
            $SampleCaptcha->CodeLength = $_POST['CodeLength'];
          }
          if (isset($_POST['CodeStyle'])) {
            $SampleCaptcha->CodeStyle = $_POST['CodeStyle'];
          }
          if (isset($_POST['ImageStyle'])) {
            $SampleCaptcha->ImageStyle = $_POST['ImageStyle'];
          }
          if (isset($_POST['CustomLightColor'])) {
            $SampleCaptcha->CustomLightColor = $_POST['CustomLightColor'];
          }
          if (isset($_POST['CustomDarkColor'])) {
            $SampleCaptcha->CustomDarkColor = $_POST['CustomDarkColor'];
          }
          if (isset($_POST['ImageFormat'])) {
            $SampleCaptcha->ImageFormat = $_POST['ImageFormat'];
          }
          if (isset($_POST['ImageWidth'])) {
            $SampleCaptcha->ImageWidth = $_POST['ImageWidth'];
          }
          if (isset($_POST['ImageHeight'])) {
            $SampleCaptcha->ImageHeight = $_POST['ImageHeight'];
          }
          if (isset($_POST['SoundStyle'])) {
            $SampleCaptcha->SoundStyle = $_POST['SoundStyle'];
          }
          if (isset($_POST['SoundFormat'])) {
            $SampleCaptcha->SoundFormat = $_POST['SoundFormat'];
          }  
        } 

        echo $SampleCaptcha->Html(); ?>
      
      <div class="validationDiv">
          <input name="CaptchaCode" type="text" id="CaptchaCode" />
          <input type="submit" name="ValidateCaptchaButton" value="Validate" id="ValidateCaptchaButton" />
          
          <?php // Captcha user input validation (only if the form was sumbitted)
            if ($_POST && isset($_POST['ValidateCaptchaButton'])) {
              $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>
    
    <fieldset id="CodeProperties">
      <legend>CAPTCHA Code Properties</legend>
      <table cellpadding="5" cellspacing="0" summary="CAPTCHA Properties layout table">
        <tr>
          <td class="left">
            <label for="Locale"><span>Locale:</span></label>
          </td>
          <td>
            <select name="Locale" id="Locale" disabled="disabled">
              <option <?php if ($SampleCaptcha->Locale == 'en-Latn-US') { echo 'selected="selected" '; } ?> value="en-Latn">en-Latn</option>
              <option <?php if ($SampleCaptcha->Locale == 'ru-Cyrl-RU') { echo 'selected="selected" '; } ?> value="ru-Cyrl">ru-Cyrl</option>
              <option <?php if ($SampleCaptcha->Locale == 'el-Grek-GR') { echo 'selected="selected" '; } ?> value="el-Grek">el-Grek</option>
              <option <?php if ($SampleCaptcha->Locale == 'he-Hebr-IL') { echo 'selected="selected" '; } ?> value="he-Hebr">he-Hebr</option>
              <option <?php if ($SampleCaptcha->Locale == 'ar-Arab') { echo 'selected="selected" '; } ?> value="ar-Arab">ar-Arab</option>
              <option <?php if ($SampleCaptcha->Locale == 'hi-Deva-IN') { echo 'selected="selected" '; } ?> value="hi-Deva">hi-Deva</option>
              <option <?php if ($SampleCaptcha->Locale == 'jp-Kana-JP') { echo 'selected="selected" '; } ?> value="jp-Kana">jp-Kana</option>
              <option <?php if ($SampleCaptcha->Locale == 'jp-Hira-JP') { echo 'selected="selected" '; } ?> value="jp-Hira">jp-Hira</option>
              <option <?php if ($SampleCaptcha->Locale == 'ko-Hang-KR') { echo 'selected="selected" '; } ?> value="ko-Hang">ko-Hang</option>
              <option <?php if ($SampleCaptcha->Locale == 'zh-cmn-Hans-CN') { echo 'selected="selected" '; } ?> value="zh-Hans">zh-Hans</option>
              <option <?php if ($SampleCaptcha->Locale == 'zh-cmn-Hant-TW') { echo 'selected="selected" '; } ?> value="zh-Hant">zh-Hant</option>
              <option <?php if ($SampleCaptcha->Locale == 'zh-cmn-Bopo-TW') { echo 'selected="selected" '; } ?> value="zh-Bopo">zh-Bopo</option>
            </select>
          </td>
          <td></td>
        </tr>
        <tr>
          <td class="left">
            <label for="CodeLength"><span>Code Length:</span></label>
          </td>
          <td>
            <input type="text" name="CodeLength" id="CodeLength" value="<?php echo $SampleCaptcha->CodeLength ?>" />
          </td>
          <td></td>
        </tr>
        <tr>
          <td class="left">
            <label for="CodeStyle"><span>Code Style:</span></label>
          </td>
          <td>
            <select name="CodeStyle" id="CodeStyle">
              <?php 
                foreach (CodeStyle::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->CodeStyle == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
            </select>
          </td>
          <td></td>
        </tr>
      </table>
    </fieldset>
    <fieldset id="ImageProperties">
        <legend>CAPTCHA Image Properties</legend>
        <table cellpadding="5" cellspacing="0" summary="CAPTCHA Properties layout table">
          <tr>
            <td class="left">
              <label for="ImageStyle"><span>Image Style:</span></label>
            </td>
            <td>
              <select name="ImageStyle" id="ImageStyle">
                <option value="">[Default]</option>
                <?php 
                foreach (ImageStyle::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->ImageStyle == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
              </select>
            </td>
            <td></td>
          </tr>
          <tr>
            <td class="left">
              <label for="CustomLightColor"><span>Custom Light Color:</span></label>
            </td>
            <td>
              <select name="CustomLightColor" id="CustomLightColor">
                <option value="">[Default]</option>
                <?php 
                foreach (HtmlColor::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->CustomLightColor == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
              </select>
            </td>
            <td></td>
          </tr>
          <tr>
            <td class="left">
              <label for="CustomDarkColor"><span>Custom Dark Color:</span></label>
            </td>
            <td>
              <select name="CustomDarkColor" id="CustomDarkColor">
                <option value="">[Default]</option>
                <?php 
                foreach (HtmlColor::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->CustomDarkColor == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
              </select>
            </td>
            <td></td>
          </tr>
          <tr>
            <td class="left">
            <label for="ImageFormat"><span>Image Format:</span></label>
          </td>
          <td>
            <select name="ImageFormat" id="ImageFormat">
              <?php 
                foreach (ImageFormat::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->ImageFormat == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name[0]; ?></option> 
                  <?php
                }
              ?>
            </select>
          </td>
          <td></td>
          </tr>
          <tr>
            <td class="left">
              <label for="ImageWidth">Image Width:</label>
            </td>
            <td>
              <input name="ImageWidth" id="ImageWidth" type="text" class="textboxSmall" value="<?php echo $SampleCaptcha->ImageWidth ?>" />&nbsp;px
            </td>
            <td></td>
          </tr>
          <tr>
            <td class="left">
              <label for="ImageHeight">Image Height:</label>
            </td>
            <td>
              <input name="ImageHeight" id="ImageHeight" type="text" class="textboxSmall" value="<?php echo $SampleCaptcha->ImageHeight ?>" />&nbsp;px
            </td>
            <td></td>
          </tr>
          </table>
        </fieldset>
        <fieldset id="AudioProperties">
        <legend>CAPTCHA Audio Properties</legend>
        <table cellpadding="5" cellspacing="0" summary="CAPTCHA Properties layout table">
          <tr>
            <td class="left">
            <label for="SoundStyle"><span>Sound Style:</span></label>
          </td>
          <td>
            <select name="SoundStyle" id="SoundStyle" disabled="disabled">
              <option value="">[Default]</option>
              <?php 
                foreach (SoundStyle::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->SoundStyle == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
            </select>
          </td>
          <td></td>
          </tr>
          <tr>
            <td class="left">
            <label for="SoundFormat"><span>Sound Format:</span></label>
          </td>
          <td>
            <select name="SoundFormat" id="SoundFormat" disabled="disabled">
              <?php 
                foreach (SoundFormat::$Names as $value => $name) { ?>
                  <option <?php if ($SampleCaptcha->SoundFormat == $value) { echo 'selected="selected"'; }?> value="<?php echo $value; ?>"><?php echo $name; ?></option> 
                  <?php
                }
              ?>
            </select>
          </td>
          <td></td>
          </tr>
        </table>
    </fieldset>
    
    
    <input type="submit" name="ApplyCaptchaSettings" value="Apply" id="ApplyButton" />

    
    <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