Php google reCAPTCHA不使用codeigniter
我正在尝试为我的网站联系人表单设置一个google recaptcha。但这对我不起作用。请帮忙 我的查看页面Php google reCAPTCHA不使用codeigniter,php,codeigniter,validation,recaptcha,Php,Codeigniter,Validation,Recaptcha,我正在尝试为我的网站联系人表单设置一个google recaptcha。但这对我不起作用。请帮忙 我的查看页面 <div class="g-recaptcha" data-sitekey="My_SITE_KEY" ></div> 控制器 public function send() { $this->load->library('curl'); $this->load->librar
<div class="g-recaptcha" data-sitekey="My_SITE_KEY" ></div>
控制器
public function send()
{
$this->load->library('curl');
$this->load->library('session');
$this->load->helper(array('form', 'url'));
$recaptchaResponse = trim($this->input->post('g-recaptcha-response'));
$userIp=$this->input->ip_address();
$secret='Secret key';
$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']){
$config = array(
'mailtype' => 'html',
'charset' => 'utf-8',
'priority' => '1'
);
$this->load->library('email',$config);
$from_email = "yy@demo.com";
$to_email = "xx@demo.co.in";
$message = '<html><body>';
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $this->input->post('email'). "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . $this->input->post('message'). "</td></tr>";
$this->email->from($from_email, 'demo');
$this->email->to($to_email);
$this->email->subject('Contact Info');
$this->email->message($message);
$this->email->send()
$this->session->set_flashdata('msg', 'Success..!');
redirect($_SERVER['HTTP_REFERER']);
}else{
$this->session->set_flashdata('msg', 'Error...! Google Recaptcha UnSuccessful');
redirect($_SERVER['HTTP_REFERER']);
}
}
公共函数send()
{
$this->load->library('curl');
$this->load->library('session');
$this->load->helper(数组('form','url');
$recaptchaResponse=trim($this->input->post('g-recaptcha-response'));
$userIp=$this->input->ip_address();
$secret='secret key';
$url=”https://www.google.com/recaptcha/api/siteverify?secret=“$secret.”&response;=“$recaptchaResponse.”&remoteip;=”$userIp;
$response=$this->curl->simple\u get($url);
$status=json_decode($response,true);
如果($status['success']){
$config=数组(
“邮件类型”=>“html”,
“字符集”=>“utf-8”,
“优先级”=>“1”
);
$this->load->library('email',$config);
$from_电子邮件=”yy@demo.com";
$to_电子邮件=”xx@demo.co.in";
$message='';
$message.=“电子邮件:”$this->input->post('Email');
$message.=“消息:”$this->input->post('message');
$this->email->from($from_email,'demo');
$this->email->to($to_email);
$this->email->subject('Contact Info');
$this->email->message($message);
$this->email->send()
$this->session->set_flashdata('msg','Success..!');
重定向($_服务器['HTTP_REFERER']);
}否则{
$this->session->set_flashdata('msg','Error…!Google Recaptcha UnSuccessful');
重定向($_服务器['HTTP_REFERER']);
}
}
我总是收到闪光信息
错误。。。!谷歌重演失败
当我打印响应时Print\r($response);退出代码>
{“成功”:false,“错误代码”:[“缺少输入响应”]}
删除代码>来自“&response;=”$recaptchaResponse。“&remoteip;=”$userIp代码>…谢谢@Lawrence\u Cherone。您保存了meremove代码>来自“&response;=”$recaptchaResponse。“&remoteip;=”$userIp代码>…谢谢@Lawrence\u Cherone。你救了我