Supriya Mk

Supriya Mk

  • NA
  • 1
  • 856

recaptcha error message

Oct 14 2015 6:34 AM
Unable to access an error message corresponding to your field name Recaptcha.(getResponse)
controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="content">
<div class="signup_wrap">
<div class="signin_form">
<?php echo form_open("user/login"); ?>
<label for="email">Email:</label>
<input type="text" id="email" name="email" value="" />
<label for="password">Password:</label>
<input type="password" id="pass" name="pass" value="" />
<input type="submit" class="" value="Sign in" />
<?php echo form_close(); ?>
</div><!--<div class="signin_form">-->
</div><!--<div class="signup_wrap">-->
<br>
<br>
<div class="reg_form">
<div class="form_title">Sign Up</div>
<div class="form_sub_title"></div>
<?php echo validation_errors('<p class="error">'); ?>
<?php echo form_open("user/registration"); ?>
<p>
<label style="color:white;" for="username">User Name:</label>
<input type="text" id="username" name="username" value="<?php echo set_value('username'); ?>" />
</p>
<p>
<label style="color:white;" for="register_as">Register as:</label>
<input type="radio" name="register_as" value="instructor" >
<b style="color:white;"> Instructor</b>
<input type="radio" name="register_as" value="student" > <b style="color:white;">Student</b>
</p>
<p>
<label style="color:white;" for="email">Your Email:</label>
<input type="text" id="email" name="email" value="<?php echo set_value('email'); ?>" />
</p>
<p>
<label style="color:white;" for="password">Password:</label>
<input type="password" id="password" name="password" value="<?php echo set_value('password'); ?>" />
</p>
<p>
<label style="color:white;" for="con_password">Confirm Password:</label>
<input type="password" id="con_password" name="con_password" value="<?php echo set_value('con_password'); ?>" />
</p>
<div class="g-recaptcha" data-sitekey="6LfDsQ4TAAAAAKfD8TqVlpKDjvlCtbqfIUPxscda"></div>
<p>
<input type="submit" class="greenButton" value="Signup" />
</p>
<?php echo form_close(); ?>
</div><!--<div class="reg_form">-->
</div><!--<div id="content">-->
 
 
 
 
 

Answers (1)