2013-10-28 92 views
0

我在我的智慧结束,不知道为什么我的代码不工作。一切似乎都很好..我在我的用户评论功能中实现了一个验证码,并使用callback_添加了验证方法。CodeIgniter验证码不工作

验证码显示在视图中,我倾倒了会话数据和输入字段数据,它们都工作。

表单验证也在captcha输入字段的情况下工作,但似乎像callback_check_captcha参数不起作用,但功能似乎罚款给我。

这里是我的控制器

function user_review($id = null , $start = 0){ 


    $check_id = $this->mdl_phone->get_phone_feature($id); 
    if ($check_id == null) { 
     $data['phone_model'] = $this->get_phone_models(); 
     $data['feature'] = null; 
     $data['title']  = 'Nothing Found'; 
     $data['main_content']= 'phone/error'; 
     echo Modules::run('templates/main',$data); 
    } else{ 

     $data['phone_model'] = $this->get_phone_models(); 

     $data['success'] = null; 
     $data['errors'] = null; 

     if($this->input->server("REQUEST_METHOD") === 'POST'){ 

      $this->load->library('form_validation'); 

      $this->form_validation->set_rules('text','Review','required|xss_clean'); 
      $this->form_validation->set_rules('captcha', 'Captcha','trim|required|callback_check_captcha'); 

      if($this->form_validation->run() == FALSE){ 
       $data['errors'] = validation_errors(); 
      }else{ 

       $user = $this->ion_auth->user()->row(); 
       $user_id = $user->id; 

       $data = array(
         'phone_id' => $id, 
         'user_id' => $user_id, 
         'text'  => strip_tags($this->input->post('text')), 
       ); 

       $this->db->insert('user_review' ,$data); 
       $data['phone_model'] = $this->get_phone_models(); 
       $data['success'] = 'Your Review has been successfully posted '; 
       $data['errors']= null; 
      } 
     } 


     // Initilize all Data at once by $id 
     $data['feature']  = $this->mdl_phone->get_phone_feature($id); 
     //$data['rating']   = $this->mdl_phone->get_user_rating($id); 
     $data['user_review'] = $this->mdl_phone->get_user_review($id , 5 , $start); 

     $this->load->library('pagination'); 

     $config['base_url']  = base_url().'phone/user_review/'.$id; 
     $config['total_rows'] = $this->mdl_phone->get_user_review_count($id); 
     $config['per_page']  = 5; 
     $config['uri_segment'] = 4; 
     $config['anchor_class'] = 'class="page" '; 

     $this->pagination->initialize($config); 

     $this->load->helper('captcha'); 

     $vals = array(
       'img_path' => './captcha/', 
       'img_url' => base_url().'captcha/', 
       'img_width' => 150, 
       'img_height' => 30, 
     ); 

     $cap = create_captcha($vals); 
     $this->session->set_userdata('captcha',$cap['word']); 

     $data['captcha']  = $cap['image']; 

     $data['title']   = $this->mdl_phone->get_phone_title($id)." User Review , Rating and Popularity"; 
     $data['main_content'] = 'phone/user_review'; 
     echo Modules::run('templates/main',$data); 
    } 
} 

function check_captcha($cap) 
{ 
    if($this->session->userdata('captcha') == $cap) 
    { 
     return true; 

    } 
    else{ 
     $this->form_validation->set_message('check_captcha', 'Security number does not match.'); 
     return false; 
    } 
} 

回答

0

波纹管CAPTHA正常参考此代码

$this->load->helper('captcha'); 
    $vals = array(
     'img_path' => './captcha/', 
     'img_url' => base_url() . '/captcha/' 
    ); 
    $cap = create_captcha($vals); 
    $data = array(
     'captcha_time' => $cap['time'], 
     'ip_address' => $this->input->ip_address(), 
     'word' => $cap['word'] 
    ); 
    $this->session->set_userdata($data); 
    $data['cap_img'] = $cap['image']; 

我觉得你的形象网址的问题,或者你不给一个文件权限的文件夹captha。