function captcha_get_code() { global $captcha_path, $captcha_chars, $captcha_wordfile, $captcha_length;
//###################### captcha mathematics start #######################function calculation(){ global $site_sess; $math = range(0,9); shuffle($math); $code = "$math[0]+$math[1]+$math[2]"; $sum = $math[0]+$math[1]+$math[2]; $site_sess->set_session_var('result', $sum); return $code;}function captcha_validate_sum($result) { global $site_sess, $captcha_enable, $user_info; if (!$captcha_enable || $user_info['user_level'] == ADMIN) { return true; } $sess_sum = trim($site_sess->get_session_var('result')); $valid_result = $sess_sum != '' && $sess_sum == $result; $site_sess->drop_session_var('result'); return $valid_result;}//###################### captcha mathematics end #########################function captcha_get_code() { global $captcha_path, $captcha_chars, $captcha_wordfile, $captcha_length,$captcha_calculation;//###################### captcha mathematics start ####################### if($captcha_calculation){ return calculation(); }//###################### captcha mathematics end #########################
$captcha_ttf = 1;
$captcha_calculation = 1; // "0" turn off captcha mathematics
.input{ font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; color: #0f5475; font-size: 11px; width: 230px;}
.input_res{ font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; color: #0f5475; font-size: 11px; width: 30px;}
$lang['captcha_required'] = 'Das Feld mit dem Bestätigungs-Code muss ausgefüllt werden.';
$lang['captcha_result'] = "Ihr Ergebnis stimmt nicht, bitte versuchen Sie es noch einmal !";$lang['captcha_desc_result'] = "Bitte tragen Sie die Rechnung aus dem Bild in das Textfeld darunter ein, und schreiben das Ergebnis rechts davon hinein.<br>Wenn Sie Probleme haben den Code zu erkennen, klicken Sie auf das Bild um ein neues zu erhalten.";
$lang['captcha_required'] = 'Please enter the verification code.';
$lang['captcha_result'] = "Your result is wrong, please try again !";$lang['captcha_desc_result'] = "Please enter the code from the image into the text field below, and write the result right inside of it.<br>If you have problems identifying the image, click on it to get a new one..";
$captcha = (isset($_POST['captcha'])) ? un_htmlspecialchars(trim($_POST['captcha'])) : "";
//###################### captcha mathematics start ####################### $result = (isset($_POST['result'])) ? intval(trim($_POST['result'])):"";//###################### captcha mathematics end #######################
if ($captcha_enable_registration && !captcha_validate($captcha)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_required']; $error = 1; }
//###################### captcha mathematics start ####################### if ($captcha_enable_registration && $captcha_calculation && !captcha_validate_sum($result)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_result']; $error = 1; }//###################### captcha mathematics end #######################
"lang_captcha_desc" => $lang['captcha_desc'],
//###################### captcha mathematics start ####################### "captcha_calculation" => (bool)$captcha_calculation, "lang_captcha_desc" => ($captcha_calculation) ? $lang['captcha_desc_result'] : $lang['captcha_desc'],//###################### captcha mathematics end #########################
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />
<input type="text" name="captcha" size="30" value="" class="captchainput" id="captcha_input" />{if captcha_calculation} = <input class="input_res" name="result" type="text" >{endif captcha_calculation}</td>
if ($captcha_enable_comments && !captcha_validate($captcha)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_required']; $error = 1; }
//###################### captcha mathematics start ####################### if ($captcha_enable_comments && $captcha_calculation && !captcha_validate_sum($result)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_result']; $error = 1; }//###################### captcha mathematics end #######################
if ($captcha_enable_postcards && !captcha_validate($captcha)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_required']; $action = "previewcard"; $main_template = "postcard_preview"; }
//###################### captcha mathematics start ####################### if ($captcha_enable_postcards && $captcha_calculation && !captcha_validate_sum($result)) { $msg .= (($msg != "") ? "<br />" : "").$lang['captcha_result']; $action = "previewcard"; $main_template = "postcard_preview";; }//###################### captcha mathematics end #######################
function getMath(){ $operators = array("+", "-", "*"); $count = count($operators) - 1; do { $num = mt_rand(2, 4); //number of numbers in final formula $formula = ""; while($num--) $formula .= ($formula !== "" ? $operators[mt_rand(0, $count)] : "") . mt_rand(0, 9); $func = create_function("", "return (" . $formula . ");" ); $compute = (int)$func(); } while($compute < 1 || $compute > 50); //we need a simple formula, so loop until the computed number is between 1 and 50 return array($formula, $compute);}