Welcome Guest, Not a member yet? Register   Sign In
Help needed with captcha !!!
#1

[eluser]sanea[/eluser]
And again hello!

I'm working on contacts page where is needed to be added number given by captcha in order for message to be send. Captcha image with the code is being generated normally but when i compare inputted by me code with that generated by captcha library(created) from session they are different and message is not being sent.
here's the captcha library code:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Captcha_lib
{    
    public function captcha_actions()
    {
        $CI =& get_instance();        
        $CI->load->helper('captcha');        
        $CI->load->helper('string');
        $rnd_str = random_string('numeric',5);
        
        $ses_data = array();
        $ses_data['rnd_captcha'] = $rnd_str;
        $CI->session->set_userdata($ses_data);
        
        $settings = array( 'word'      => $rnd_str,
                           'img_path'  => './img/captcha/',
                           'img_url'   => base_url().'img/captcha/',
                           'font_path' => './system/fonts/cour.ttf',
                           'img_width' => 120,
                           'img_height'=> 30,
                           'expiration'=> 100);
        
        $captcha = create_captcha($settings);      
        $imgcode = $captcha['image'];
        return $imgcode;        
    }    
}
?>

and the part of code from controller calling that data:
Code:
$this->form_validation->set_rules($this->pages_model->
            contact_rules);
            
            $val_res = $this->form_validation->run();
            
            if($val_res == TRUE)
            {
                $entered_captcha = $this->input->post('captcha');
                

                
                if($entered_captcha == $this->session->userdata(
                'rnd_captcha'))
                {
                    $this->load->library('typography');
                    
                    $name = $this->input->post('name');
                    
                    $email = $this->input->post('email');
                    
                    $topic = $this->input->post('topic');
                    
                    $text = $this->input->post('message');
                    
                    $text = wordwrap($text,70);
                    
                    $text = $this->typography->auto_typography($text,TRUE);
                    
                    $text = strip_tags($text);
                    
                    $address = "[email protected]";
                    
                    $subject = "Question from feedback";
                    
                    $message = "
Written by: $name\nTopic: $topic\nMessage:\n$text\nE-Mail: $email\n";
                    
                    mail($address,$subject,$message,
                    "Content-type:text/plain;charset = windows-1251\r\n");
                    
                    $data['info'] = 'Your message was sent';
                    
                    $name = 'info';
                    
                    $this->display_lib->user_info_page($data,$name);              
                  
                    
                }
                else
                {
                    $data['imgcode'] = $this->captcha_lib->
                    captcha_actions();
                    
                    $data['info'] = 'The numbers you entered do not match';
                    
                    $name = 'pages/contact';
                    
                    $this->display_lib->user_page($data,$name);
                }

entered data is validated an when it comes to be compared:
Quote:if($entered_captcha == $this->session->userdata('rnd_captcha'))
it acts like they are different and showing me
Code:
$data['info'] = 'The numbers you entered do not match';

thx in advance!




Theme © iAndrew 2016 - Forum software by © MyBB