Unable to access an error message corresponding to your field name Recaptcha.(getResponse)
controller
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
if(($this->session->userdata('username')!=""))
{
$this->welcome();
}
else{
$data['title']= 'zero2world';
$this->load->view('header_view',$data);
$this->load->view("registration_view.php", $data);
$this->load->view('footer_view',$data);
}
}
public function welcome()
{
$data['title']= 'Welcome';
$this->load->view('header_view',$data);
$this->load->view('welcome_view.php', $data);
$this->load->view('footer_view',$data);
}
public function login()
{
$email=$this->input->post('email');
$password=md5($this->input->post('password'));
$result=$this->user_model->login($email,$password);
if($result) $this->welcome();
else $this->index();
}
public function thank()
{
$data['title']= 'Thank';
$this->load->view('header_view',$data);
$this->load->view('thank_view.php', $data);
$this->load->view('footer_view',$data);
}
public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]');
$this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_rules('register_as','Register_as');
$this->form_validation->set_rules('g-recaptcha-response','Recaptcha','required|callback_getResponse');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->user_model->add_user();
$this->thank();
}
}
public function getResponse($str)
{
$secret_key="secret key";
$ip_user=$this->input->ip_address();
$url="https://www.google.com/recaptcha/api/siteverify?secret=".$secret_key."&response=".$str."&remoteip=".$ip_user;
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$data = curl_exec($ch);
curl_close($ch);
$status= json_decode($data,true);
if($status['success'])
{
return true;
}
else
{
$this->session->set_flashdata('recaptcha', 'incorrect captcha');
return false;
}
}
public function logout()
{
$newdata = array(
'user_id' =>'',
'user_name' =>'',
'user_email' => '',
'logged_in' => FALSE,
);
$this->session->unset_userdata($newdata );
$this->session->sess_destroy();
$this->index();
}
}
?>
model
class User_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
function login($email,$password)
{
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("user");
$query=$this->db->get("reginstructor");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
'user_id' => $rows->id,
'user_name' => $rows->username,
'user_email' => $rows->email,
'instructor' => $rows->instructor,
'student' =>$rows->student,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
public function add_user()
{
$data=array(
'username'=>$this->input->post('username'),
'email'=>$this->input->post('email'),
'password'=>md5($this->input->post('password')),
'register_as'=>$this->input->post('register_as'),
'hash' => md5(rand(0, 1000))
);
//instructor verification
if($data['register_as'] == "instructor")
{
$this->db->insert('reginstructor',$data);
}
//user part
else
{
$this->db->insert('user',$data);
}
}
public function verify_user($email) {
$data = array('is_verified' => 1);
$this->db->where('email', $email);
$this->db->update('user', $data);
}
}
?>
view
Sign Up
'); ?>
Instructor
Student
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sujeet SumanPosted Oct 14, 2015, 7:53 AM