google captcha not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: google captcha not working (/showthread.php?tid=71108) |
google captcha not working - kvanaraj - 07-07-2018 my view file ********* <div class="g-recaptcha" data-sitekey=""> Controller file *********** public function loginMe() { $this->load->library('form_validation'); $this->load->library('session'); $this->load->helper('url'); $this->form_validation->set_rules('regno', 'regno','required'); $this->form_validation->set_rules('dob', 'dob','required'); if($this->form_validation->run() == FALSE) { $this->index(); //echo "test"; } else { $regno = $this->security->xss_clean($this->input->post('regno')); //echo $regno; $dob = $this->input->post('dob'); //echo $dob; $result = $this->login_model->loginMe($regno, $dob); //print_r($result); if(!empty($result)) { $lastLogin = $this->login_model->lastLoginInfo($result->regno); print_r($lastLogin); $sessionArray = array('userId'=>$result->regno, 'role'=>$result->roleId, 'roleText'=>$result->role, 'name'=>$result->name, 'lastLogin'=> $lastLogin->createdDtm, 'isLoggedIn' => TRUE ); print_r($sessionArray); $this->session->set_userdata($sessionArray); unset($sessionArray['userId'], $sessionArray['isLoggedIn'], $sessionArray['lastLogin']); $loginInfo = array("userId"=>$result->regno, "sessionData" => json_encode($sessionArray), "machineIp"=>$_SERVER['REMOTE_ADDR'], "userAgent"=>1, "agentString"=>1, "platform"=>'A'); $this->login_model->lastLogin($loginInfo); redirect('/dashboard'); } else { $this->session->set_flashdata('error', 'Email or password mismatch'); redirect('/login'); } } } public function recaptcha($str='') { $google_url="https://www.google.com/recaptcha/api/siteverify"; $secret=' '; $ip=$_SERVER['REMOTE_ADDR']; $url=$google_url."?secret=".$secret."&response=".$str."&remoteip=".$ip; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16"); $res = curl_exec($curl); curl_close($curl); $res= json_decode($res, true); //reCaptcha success check if($res['success']) { return TRUE; } else { $this->form_validation->set_message('recaptcha', 'The reCAPTCHA field is telling me that you are a robot. Shall we give it another try?'); return FALSE; } } I want to add google captcha with validation of only (Regno field and Google captcha) I tried with these possibilities. whats wrong in my code? RE: google captcha not working - enlivenapp - 07-07-2018 Quote:I want to add google captcha with validation of only (Regno field and Google captcha) remove PHP Code: $this->form_validation->set_rules('dob', 'dob','required'); and add the recaptcha function as a validation callback. https://codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods |