<?php
require 'CaptchasDotNet.php';
// Construct the captchas object. Replace 'demo' and 'secret' with
// the values you receive upon registration at
http://captchas.net.
$captchas = new CaptchasDotNet ('***', '***');
// The website template.
$template = <<<EOT
<html><head><title>@TITLE@</title></head><h1>@TITLE@</h1>@BODY@</html>
EOT;
// Read the form values
$message = $_REQUEST['message'];
$password = $_REQUEST['password'];
$random_string = $_REQUEST['random'];
// Check the random string to be valid and return an error message
// otherwise.
if (!$captchas->validate ($random_string))
{
$body = 'Every CAPTCHA can only be used once. The current '
. 'CAPTCHA has already been used. Try again.';
}
// Check, that the right CAPTCHA password has been entered and
// return an error message otherwise.
elseif (!$captchas->verify ($password))
{
$body = 'Wrong Password entered. Aren\'t you human? Try again.';
}
// Return a success message
else
{
$body = 'Your message was verified to be entered by a human and is "'
. $message . '"';
}
// Replace the title in the template
$template = str_replace ('@TITLE@', 'Sample PHP CAPTCHA Check', $template);
// Replace the body in the template
$template = str_replace ('@BODY@', $body, $template);
echo $template
?>