2013-10-28 132 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。