'plus',2=>'minus',3=>'divided by',4=>'times'); /** * @throws Exception */ function Form($html){ $operator_key = array_rand($this->operators); $operator = $this->operators[$operator_key]; $asm_1 = random_int(1,10); $asm_3 = random_int(1,10); if ($operator_key == 3) { $asm_1 = $asm_1 * $asm_3; } $inputs = array(); $inputs[] = ' '; $inputs[] = ' '; $inputs[] = ' '; shuffle($inputs); ob_start(); echo implode('',$inputs); echo ''; echo $asm_1; echo ' '; echo gpOutput::GetAddonText($operator); echo ' '; echo $asm_3; echo ' '; echo gpOutput::GetAddonText('equals'); echo ' '; echo ''; $html .= ob_get_clean(); return $html; } function message_alert($msg) { echo ""; } function Check($passed){ $message = gpOutput::SelectText('Sorry, your answer to the verification challenge was incorrect. Please try again.'); if( empty($_POST['asm_1']) || empty($_POST['asm_2']) || empty($_POST['asm_3']) ){ $this->message_alert($message . ' (1)'); return false; } $operator_key = $_POST['asm_2']; if( !isset($this->operators[$operator_key]) ){ $this->message_alert($message . ' (2)'); return false; } switch($operator_key){ case 1: $result = $_POST['asm_1'] + $_POST['asm_3']; break; case 2: $result = $_POST['asm_1'] - $_POST['asm_3']; break; case 3: $result = $_POST['asm_1'] / $_POST['asm_3']; break; case 4: $result = $_POST['asm_1'] * $_POST['asm_3']; break; } $compare = $_POST['asm_4']; //message('result: '.$result.' vs submitted: '.$compare); if( $compare != $result ){ $this->message_alert($message . ' (3)'); return false; } //message('passed'); return $passed; } }