Welcome Guest, Not a member yet? Register   Sign In
Captcha helper problem
#4

[eluser]mi6crazyheart[/eluser]
Don't know how u doing the things. But, i think this thing will help u...

Controller part
----------------
Code:
$this->form_validation->set_rules('securityCode', 'Security Code', 'trim|required|callback_Captcha_check');

//-----Call back function for checking given captcha code is valid or not-----
        function Captcha_check($str)
        {
            // First, delete old captchas
            $expiration = time()-7200; // Two hour limit
            // $DB->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);        
            $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);
        
            // Then see if a captcha exists:
            $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
            $binds = array($this->input->post('securityCode'), $this->input->ip_address(), $expiration);
            $query = $this->db->query($sql, $binds);
            $row = $query->row();
        
            if ($row->count == 0){
                $this->form_validation->set_message('Captcha_check', 'Security code miss match. Try again');
                return FALSE;
                //echo "You must submit the word that appears in the image";
            }            
        }


VIEW part
-------------
Code:
$vals = array(
            'word'            => '',
            'img_path'        => './captcha/',
            //'img_url'        => 'http://localhost/vb/captcha/',
            'img_url'        => base_url().'captcha/',
            'font_path'    => './path/to/fonts/texb.ttf',
            'img_width'    => '150',
            'img_height'    => 30,
            'expiration'    => 7200
            );

            $cap = create_captcha($vals);
            
            $data = array(
                'captcha_time'    => $cap['time'],
                'ip_address'    => $this->input->ip_address(),
                'word'             => $cap['word']
            );

            $query = $this->db->insert_string('captcha', $data);
            $this->db->query($query);

            echo $cap['image'];

Hope this much will help...


Messages In This Thread
Captcha helper problem - by El Forum - 07-05-2011, 01:39 AM
Captcha helper problem - by El Forum - 07-05-2011, 07:05 AM
Captcha helper problem - by El Forum - 07-05-2011, 10:26 AM
Captcha helper problem - by El Forum - 07-05-2011, 11:23 AM
Captcha helper problem - by El Forum - 07-05-2011, 11:52 AM
Captcha helper problem - by El Forum - 07-05-2011, 12:21 PM
Captcha helper problem - by El Forum - 07-05-2011, 12:30 PM
Captcha helper problem - by El Forum - 07-05-2011, 08:33 PM
Captcha helper problem - by El Forum - 07-05-2011, 08:49 PM
Captcha helper problem - by El Forum - 07-06-2011, 12:39 AM
Captcha helper problem - by El Forum - 07-06-2011, 09:30 AM
Captcha helper problem - by El Forum - 07-06-2011, 09:57 AM
Captcha helper problem - by El Forum - 07-06-2011, 11:26 AM
Captcha helper problem - by El Forum - 07-06-2011, 01:52 PM
Captcha helper problem - by El Forum - 07-06-2011, 11:59 PM
Captcha helper problem - by El Forum - 07-07-2011, 12:31 AM
Captcha helper problem - by El Forum - 07-07-2011, 01:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB