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.

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.

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) {
"<h1><font color='red'>$error</font></h1><br />";

        <form name="capter" action="index.php?page=liveExample" method="post">
           <th>What is this result pilgrim?: '
           <td><input type="text" value="" name="captcha" /></td>
           <td><input type="submit" value="Let me prove you that I am human!" /></td>
$_SESSION['answer'] = $numcap->getAnswer();
Introduction (Previous) Information about the Text_CAPTCHA_Numeral and inner workings (Next)
Last updated: Wed, 16 Apr 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.