Ignore:
Timestamp:
Jan 26, 2006 8:19:32 PM (18 years ago)
Author:
scdev
Message:

${1}

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Captcha.inc.php

    r52 r53  
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    99 * @version 1.0
     10-------------------------------------------------------------------------------------
     11// Example.
     12
     13// Instantiate new Captcha. This automatically generates a new 4-digit captcha number.
     14$captcha = new Captcha();
     15
     16<!-- HTML form for captcha -->
     17<label for="sc-captcha"><?php echo _("Reverse Turing Test") ?></label>
     18<p class="help"><?php echo _("Please type the following number to prove you are a human. This is a measure to prevent spam robots from submitting this form.") ?></p>
     19<pre style="font-size: 0.5em;"><?php $captcha->printAsciiNumber() ?></pre>
     20<?php $captcha->printForm() ?>
     21-------------------------------------------------------------------------------------
    1022 */
    1123class Captcha {
    1224
    1325    var $secret_key = 'some random seed text for the md5';
     26    var $random_number;
    1427    var $ascii_numbers = array(
    1528        array(
     
    95108        )
    96109    );
     110   
     111    /**
     112     * Constructor. Initialized new random number.
     113     *
     114     * @access  public
     115     * @author  Quinn Comendant <quinn@strangecode.com>
     116     * @since   20 Jan 2006 13:08:22
     117     */
     118    function Captcha()
     119    {
     120        $this->random_number = $this->_getRandomNumber();
     121    }
    97122
    98123    /**
     
    129154
    130155    /**
     156     * Prints the captcha ASCII numbers.
     157     *
     158     * @access  public
     159     * @author  Quinn Comendant <quinn@strangecode.com>
     160     * @since   07 Dec 2005 22:09:04
     161     */
     162    function printAsciiNumber()
     163    {
     164        $ascii = $this->getAsciiNumber($this->random_number);
     165        ?><pre name="sc-captcha" id="sc-captcha"><?php echo $ascii ?></pre><?php
     166    }
     167
     168    /**
    131169     * Prints a form to enter captcha, including the required hidden hash form.
    132170     *
     
    137175    function printForm()
    138176    {
    139         $number = $this->_getRandomNumber();
    140         $hash = $this->_getMD5key($number);
    141         $ascii = $this->getAsciiNumber($number);
     177        $hash = $this->_getMD5key($this->random_number);
    142178        ?>
    143         <label for="sc-captcha"><?php echo _("Reverse Turing Test") ?></label>
    144         <p class="help"><?php echo _("Please type the following number to prove you are a human. This is a measure to prevent spam robots from submitting this form.") ?></p>
    145         <pre style="font-size: 0.5em;"><?php echo $ascii ?></pre>
    146         <input name="sc-captcha" id="sc-captcha" type="text" />
    147         <input name="sc-captcha-hash" type="hidden" value="<?php echo $hash ?>" />
     179        <input name="sc-captcha-input" id="sc-captcha-input" type="text" />
     180        <input name="sc-captcha-hash" id="sc-captcha-hash" type="hidden" value="<?php echo $hash ?>" />
    148181        <?php
    149182    }
     
    160193    function valid()
    161194    {
    162         $number = getFormData('sc-captcha');
     195        $number = getFormData('sc-captcha-input');
    163196        $hash = getFormData('sc-captcha-hash');
    164197
Note: See TracChangeset for help on using the changeset viewer.