php - New Google reCAPTCHA keeps failing to verify with localhost -
new google recaptcha using codeigniter 2.2.2 everytime try run test, returns false result after loading long time following warning message:
a php error encountered
severity: warning
message: file_get_contents(https://www.google.com/recaptcha/api/siteverify?secret=publickey&response=03ahj_vuvowcxikqgozxeeowvdxmjyrbsh9hywpbxg1ymbtths8ginjc5yeqog0fvikdpy3gxemqvrb6dt965o0larl2rrdp-u6m9y9dsfddvz55vwsewe4--m0nfssykjz3et6zitkh7mnsdii1lltprn7vaqmcglk3lw2hs4q8tmdhjtw-tecmcrboncctcvmn4ghnwugzszufulopxalshevkbhspzb5snglnakz5rrf591ll9ss8nrzerfvo3eyspw_ccg26udhpmjw5y5b_3nznbyzqpmf0eiimy5w3rk2fjjrpw2g8kj98cv1b1xjcxbgml7ucnzrmc7wdzhzfoi2jaeuebnwqkqjvsgxsglgkewz1clpiqwzyzrlwepgo2zpkri6lrilnmic0dtmhm7u172lgelgjbnkfaw29aq8wtocwc2tztwltn_8mq9srs_mhhs7iag&remoteip=127.0.0.1): failed open stream: connection attempt failed because connected party did not respond after period of time, or established connection failed because connected host has failed respond.
filename: controllers/cap.php
here html code
<!doctype html> <html lang="en"> <head> <title>test</title> </head> <body> <form action="validation" method="post"> <label for="name">name:</label> <input name="name" required><br /> <label for="email">email:</label> <input name="email" type="email" required><br /> <div class="g-recaptcha" data-sitekey="my_public_key"></div> <input type="submit" value="submit" /> </form> <!--js--> <script src='https://www.google.com/recaptcha/api.js'></script> </body> </html>
here php file:
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class cap extends ci_controller { public function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->database(); $this->load->model('users_model', 'user'); $this->lang->load("message",$this->session->userdata('language')); } public function index() { $this->load->view("cap"); } public function validation() { $email;$comment;$captcha; if(isset($_post['email'])){ $email=$_post['email']; }if(isset($_post['comment'])){ $email=$_post['comment']; }if(isset($_post['g-recaptcha-response'])){ $captcha=$_post['g-recaptcha-response']; } if(!$captcha){ echo '<h2>please check the captcha form.</h2>'; exit; } remoteip=".$_server['remote_addr']); $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=myprivatekey&response=".$captcha."&remoteip=".$_server['remote_addr']), true); if($response['success'] == false) { echo '<h2>wrong</h2>'; }else { echo '<h2>correct</h2>'; } } } ?>
(of course generated public , private key through google api webpage)
any idea guys? need turn on curl or in php?
it's possible allow_url_fopen = off
in php.ini
, preventing file_get_contents
opening urls.
you use curl this, this:
$fields = array( 'secret' => "mysecretkey", 'response' => $captcha, 'remoteip' => $_server['remote_addr'] ); $ch = curl_init("https://www.google.com/recaptcha/api/siteverify"); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_timeout, 15); curl_setopt($ch, curlopt_postfields, http_build_query($fields)); $response = json_decode(curl_exec($ch)); curl_close($ch);
Comments
Post a Comment