아래의 POST 데이터를 받아줄 메소드에 아래와 같이 입력해주고,
$this->form_validation->set_rules('g-recaptcha-response', '보안인증', 'trim|required|callback__check_recaptcha');
컨트롤러 안에 아래의 메소드를 넣어준다. $secret 변수에 구글의 reCaptcha Secret Key를 넣어준다.
function _check_recaptcha($code) { // 구글 reCaptcha $recaptchaResponse = $code; $user_ip = $this->input->ip_address(); $secretkey = 'abcdefghijklmnopqrstuvwxyz'; $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $secretkey . '&response=' . $recaptchaResponse . '&remoteip=' . $user_ip; $this->load->library('curl'); $response = $this->curl->simple_get($url); $status = json_decode($response, true); if ($status['success']) { return true; } else { $this->form_validation->set_message('_check_recaptcha', '보안 인증에 실패 했습니다.'); return false; } return true; }
그리고 view의 폼 안에 삽입한다. data-sitekey에는 구글 reCapcha siteky를 넣어준다.
<div class="g-recaptcha" data-sitekey="abcdefghijklmnopqrstuvwxyz"></div>
새댓글 등록