Changeset 53 for trunk/lib/Captcha.inc.php
- Timestamp:
- Jan 26, 2006 8:19:32 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Captcha.inc.php
r52 r53 8 8 * @author Quinn Comendant <quinn@strangecode.com> 9 9 * @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 ------------------------------------------------------------------------------------- 10 22 */ 11 23 class Captcha { 12 24 13 25 var $secret_key = 'some random seed text for the md5'; 26 var $random_number; 14 27 var $ascii_numbers = array( 15 28 array( … … 95 108 ) 96 109 ); 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 } 97 122 98 123 /** … … 129 154 130 155 /** 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 /** 131 169 * Prints a form to enter captcha, including the required hidden hash form. 132 170 * … … 137 175 function printForm() 138 176 { 139 $number = $this->_getRandomNumber(); 140 $hash = $this->_getMD5key($number); 141 $ascii = $this->getAsciiNumber($number); 177 $hash = $this->_getMD5key($this->random_number); 142 178 ?> 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 ?>" /> 148 181 <?php 149 182 } … … 160 193 function valid() 161 194 { 162 $number = getFormData('sc-captcha ');195 $number = getFormData('sc-captcha-input'); 163 196 $hash = getFormData('sc-captcha-hash'); 164 197
Note: See TracChangeset
for help on using the changeset viewer.