Home » Text » Text_CAPTCHA_Numeral » Manual
Implementation of mathematic operation CAPTCHAs (Completely Automated Public Turing tests to tell Computers and Humans Apart).
Introduction
This package provides the functionality to create Numeral CAPTCHAs (Completely Automated Public Turing tests to tell Computers and Humans Apart). Features include:
- Creating numerical Captchas
- Generic information about the Text_CAPTCHA_Numeral
The package creates numeral CAPTCHAs; due to the stateless nature of the HTTP protocol, the logic to secure a webpage using the package must be specifically implemented. See the usage example for detailled information.
Example
The following example implements the standard use of a CAPTCHA: Submitted form data is only evaluated when a CAPTCHA has been solved correctly.
Creating a Numeral CAPTCHA
This example is just to show you how to generate a simple mathematic operation with Text_CAPTCHA_Numeral.
<?php
require_once 'Text/CAPTCHA/Numeral.php';
$num = new Text_CAPTCHA_Numeral;
$operation = $num->getOperation();
/**
* This will print the mathematical operation
* that has been generated by the package.
*/
print $operation;
?>
Securing a form with a Numeral CAPTCHA
This example will show you how to secure a form using the numeral captcha. It generates an operation and stores its result into a session variable.
<?php
require_once 'Text/CAPTCHA/Numeral.php';
$numcap = new Text_CAPTCHA_Numeral;
if (isset($_POST['captcha']) && isset($_SESSION['answer'])) {
if ($_POST['captcha'] == $_SESSION['answer']) {
$errors[] = 'Ok... You might be human...';
} else {
$errors[] = 'You are dumb or not human';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
print "<h1><font color='red'>$error</font></h1><br />";
}
}
print '
<form name="capter" action="index.php?page=liveExample" method="post">
<table>
<tr>
<th>What is this result pilgrim?: '.$numcap->getOperation().'</th>
<td><input type="text" value="" name="captcha" /></td>
</tr>
<tr>
<th/>
<td><input type="submit" value="Let me prove you that I am human!" /></td>
</tr>
</form>
';
$_SESSION['answer'] = $numcap->getAnswer();
?>
Information about the Text_CAPTCHA_Numeral and inner workings
Text_CAPTCHA_Numeral gives you the ability to generate numerical mathematical captchas.
- getOperation() generates the operation that is going to be shown to the end user. getAnswer() Gets the answer of the generated operation's answer.