Welcome Guest, Not a member yet? Register   Sign In
Code snippet: Captcha revisited
#1

[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>&lt;input type='text' name='captcha' value='' style='margin-top:10px;' /&gt;".$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 Wink
#2

[eluser]sikkle[/eluser]
humm, do some test, and maybe add that to wiki captcha section, that would make sense to let people use it.

thanks !




Theme © iAndrew 2016 - Forum software by © MyBB