[eluser]Maxximus[/eluser]
I know some of you don't like Captcha at all, and can be quite annoying for the user, especially with 'funny' fonts and autogenerated values.
Still it can help to prevent spam. Different forms have been thought out, and the calculate version I personally like most. For that reason I combined the standard CI Captcha with a small snippet in the view.
Code:
$operator = array('+', '-');
$captcha_value = mt_rand(20, 100).$operator[mt_rand(0, count($operator)-1)].mt_rand(1, 20);
$this->load->plugin('captcha');
$vals = array(
'word' => $captcha_value.'= ?',
'img_path' => './assets/captcha/',
'img_url' => '/assets/captcha/',
'font_path' => './assets/system/fonts/Arial.ttf',
'img_width' => 180,
'img_height' => 33,
);
$cap = create_captcha($vals);
eval("\$captcha_outcome = $captcha_value;");
$data = array(
'captcha_id' => '',
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $captcha_outcome
);
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
echo "<label for='captcha'>Calculate sum:</label><span><input type='text' name='captcha' value='' style='margin-top:10px;' />".$cap['image']."</span>";
You can create your own $captcha_vals array, or add operators. Just make sure your users can calculate the outcome without a calculator