2010-02-01 3 views
2

를 웹 호스트에 업로드하지만 경우에만 (그리고 하단의 1.7 배 수정) 로컬에서 작업 할 때 http://codeigniter.com/forums/viewthread/94299/reCAPTCHA를 검증 CodeIgniter는 슬로우되지 않는 - 온라인 다음 가이드를 사용하여

reCAPTCHA를 검증은 잘 작동합니다 (모두 내 창에서 테스트 기계 및 친구 OSX 기계) 그러나 업로드 할 때 너무 내 서버와 그의 웹 호스트 recaptch에 대한 유효성 검사 루틴 페이지의 다른 유효성 검사를하더라도 확인하지 나타납니다. 그러나 오류가 발생하지 않으며 코드를 살펴본 후 잘못된 점을 찾을 수 없습니다. 아무도 내가 무슨 일이 일어나고 있는지 알 수 있다면 크게 감사하겠습니다. 여기

는/라이브러리/MY_Form_Validation.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class MY_Form_Validation extends CI_Form_Validation 
{ 

    function MY_Form_Validation() 
    { 
     parent::CI_Form_Validation(); 
    } 

    function recaptcha_matches() { 
     $CI = & get_instance(); 
     $CI->config->load('recaptcha'); 
     $public_key = $CI->config->item('recaptcha_public_key'); 
     $private_key = $CI->config->item('recaptcha_private_key'); 
     $response_field = $CI->input->post('recaptcha_response_field'); 
     $challenge_field = $CI->input->post('recaptcha_challenge_field'); 
     $response = recaptcha_check_answer($private_key, $_SERVER['REMOTE_ADDR'], $challenge_field, $response_field); 

     if ($response->is_valid) { 
      return TRUE; 
     } 
     else { 
      $this->recaptcha_error = $response->error; 
      $this->set_message('recaptcha_matches', 'The %s is incorrect. Please try again.'); 
      return FALSE; 
     } 
    } 

응용 프로그램/도우미/recaptcha_helper.php이

응용 프로그램을 처리하는 클래스이다

http://pastebin.com/m352494c3

응용 프로그램/컨트롤러/forum.php - 내 코드에서 포스트 스레드 방식

public function add_thread($category_id = null) 
{ 
    $category = $this->forums->get_category($category_id); 
    if ($category == false) 
    { 
     $this->template->set('title', 'Invalid Page'); 
     $data['error_message'] = "Invalid category to add thread too"; 
     $this->template->load('template', 'error', $data); 
     return; 
    } 

    $user = $this->users->get($this->session->userdata('user_id')); 

    $data['category_id'] = $category['id']; 
    $data['category_title'] = $category['category_title']; 
    $data['loggedin'] = $this->session->userdata('loggedin'); 

    $this->form_validation->set_rules('thread_title', 'Title', 'required'); 
    $this->form_validation->set_rules('thread_body', 'Body', 'required'); 

    if (!$data['loggedin']) 
    { 
     $this->form_validation->set_rules('recaptcha_challenge_field', 'answer to the security question', 'recaptcha_matches'); 
    } 

    if ($this->form_validation->run() == FALSE) 
    { 
     $this->template->load('template', 'forums/add_thread', $data); 
     return; 
    } 

    $thread['thread_title'] = $this->input->post('thread_title'); 
    $thread['thread_body'] = $this->input->post('thread_body'); 
    if($user==false){ 
     $thread['user_id'] = -1; 
    }else{ 
     $thread['user_id'] = $user->id; 
    } 
    $thread['posted_date'] = date("Y-m-d H:i:s"); 
    $thread['category_id'] = $category_id; 

    $this->forums->add_thread($thread); 
    redirect('forums/view/' . $category_id, 'refresh'); 
} 

답변

0

, 나는 보통 이런 식으로 쓰기 :

$response = recaptcha_check_answer($private_key, $CI->input->ip_address(), $challenge_field, $response_field); 

$CI->input->ip_address() 클라이언트 IP 주소를 감지하는보다 정교한 방법이있다. REMOTE_ADDR 만 사용하는 것보다

또한 개인 키와 공개 키가 서버의 도메인 이름과 일치하는지 확인하거나 전역 키를 사용하십시오.

관련 문제