Project

General

Profile

« Previous | Next » 

Revision 227

Added by ryan about 19 years ago

Finished correct Captcha implementation in form mod

View differences:

view.php
110 110
<?php
111 111

  
112 112
// Get settings
113
$query_settings = $database->query("SELECT header,field_loop,footer FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
113
$query_settings = $database->query("SELECT header,field_loop,footer,use_captcha FROM ".TABLE_PREFIX."mod_form_settings WHERE section_id = '$section_id'");
114 114
if($query_settings->numRows() > 0) {
115 115
	$fetch_settings = $query_settings->fetchRow();
116 116
	$header = str_replace('{WB_URL}',WB_URL,$fetch_settings['header']);
117 117
	$field_loop = $fetch_settings['field_loop'];
118
	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
118
	$footer = str_replace('{WB_URL}',WB_URL,$fetch_settings['footer']);
119
	$use_captcha = $fetch_settings['use_captcha'];
119 120
} else {
120 121
	$header = '';
121 122
	$field_loop = '';
......
182 183
		if (isset($tmp_field_loop)) $field_loop = $tmp_field_loop;
183 184
	}
184 185
}
186

  
187
// Captcha
188
if($use_captcha) {
189
	$_SESSION['captcha'] = '';
190
	for($i = 0; $i < 5; $i++) {
191
		$_SESSION['captcha'] .= rand(0,9);
192
	}
193
	?><tr><td class="field_title">Verification:</td><td>
194
	<table cellpadding="2" cellspacing="0" border="0">
195
	<tr><td><img src="<?php echo WB_URL; ?>/include/captcha.php" alt="Captcha" /></td>
196
	<td><input type="text" name="captcha" maxlength="5" /></td>
197
	</tr></table>
198
	</td></tr>
199
	<?php
200
}
185 201

  
186 202
// Print footer
187 203
echo $footer;
......
251 267
	
252 268
	// Captcha
253 269
	if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) { /* Make's sure GD library is installed */
254
		if(isset($_POST['captcha']) AND $_POST['CAPTCHA']!=''){
255
			// User-supplied captcha
256
			$user_captcha = $_POST['captcha'];
257
			// Computer generated
258
			if(isset($_SESSION['captcha'])) {
259
				$system_captcha = $_SESSION['captcha'];
260
			}
270
		if(isset($_POST['captcha']) AND $_POST['captcha'] != ''){
261 271
			// Check for a mismatch
262
			if($user_captcha != $system_captcha) {
272
			if(!isset($_POST['captcha']) OR !isset($_SESSION['captcha']) OR !$_POST['captcha'] == $_SESSION['captcha']) {
263 273
				$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
264
			} else {
265
				unset($_SESSION['captcha']);
266 274
			}
267 275
		} else {
268 276
			$captcha_error = $MESSAGE['MOD_FORM']['INCORRECT_CAPTCHA'];
269 277
		}
270 278
	}
279
	if(isset($_SESSION['catpcha'])) { unset($_SESSION['captcha']); }
271 280
	
272 281
	// Addslashes to email body - proposed by Icheb in topic=1170.0
273 282
	// $email_body = $wb->add_slashes($email_body);

Also available in: Unified diff