次のガイドをオンラインで使用する(および下部にある1.7x修正)http://codeigniter.com/forums/viewthread/94299/
Recaptcha検証は、ローカルで作業している場合(Windowsマシンと友人のOSXマシンの両方でテスト済み)にうまく機能しますが、サーバーと彼のWebホストの両方をアップロードすると、ページ上の他の検証がチェックされても、recaptchの検証ルーチンがチェックされないように見えます。ただし、エラーはスローされず、コードを調べたところ、何が問題になっているのかを見つけることができませんでした。誰かが私が何が起こっているのかを知るのを手伝ってくれるなら、それは大いにありがたいです。
これを扱うクラスは次のとおりです
application / libraries / 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;
}
}
application / helpers / recaptcha_helper.php
application / controllers/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');
}