controller:test.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller
{
function __construct()
{
parent :: __construct();
$this->load->helper(array('form', 'url'));
$this->load->model('Fetch_data');
}
public function login()
{
$this->load->view('login');
}
public function signin()
{
$firstName = trim($this->input->post('fname'));
$email = trim($this->input->post('email'));
$phone = trim($this->input->post('mobile'));
$recaptchaResponse = trim($this->input->post('g-recaptcha-response'));
$userIp=$this->input->ip_address();
$secret='******************************';
$url="https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response;=".$recaptchaResponse."&remoteip;=".$userIp;
$response = $this->curl->simple_get($url);
$status= json_decode($response, true);
if($status['success'])
{
$this->session->set_flashdata('flashSuccess', 'Google Recaptcha Successful');
}
else
{
$this->session->set_flashdata('flashSuccess', 'Sorry Google Recaptcha Unsuccessful!!');
}
redirect(base_url('index.php/test/login'));
}
}
view:login.php
<?php echo $this->session->flashdata('message');?>
<div class="error"><strong><?=$this->session->flashdata('flashSuccess')?></strong></div>
<hr/>
<form method="post">
<div class="form-group">
<input type="text" name="fname" id="fname" placeholder="Your First Name" class="text-line"/>
</div>
<div class="form-group">
<input type="text" name="email" id="email" placeholder="Your Email" class="text-line"/>
</div>
<div class="form-group">
<input type="text" name="mobile" id="mobile" placeholder="Your Mobile" class="text-line"/>
</div>
<div class="g-recaptcha" data-sitekey="*********************************"></div>
<div class="form-group">
<input type="submit" name="signup" id="signup" value="Sign Up" class="btn btn-warning"/>
</div>
</form>
在此代码中,我使用的是google recaptcha。当我检查recaptcha复选框 然后它无法显示消息,即Google Recaptcha成功或对不起Google Recaptcha不成功。我不知道为什么?任何人都可以告诉我我做错了吗?