Reputation: 113
I am having some issue adding the reCAPTCHA to my website. The code below works fine on my local host but not on my remote server.
if (isset($_POST['g-recaptcha-response'])) {
$secret = '6LcUahkTAOlz-3iYApxHVjUC6wSc30G';
$ip = $_SERVER['REMOTE_ADDR'];
//var_dump($ip); works fine on both local and remote
$captcha = $_POST['g-recaptcha-response'];
$rsp = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip=$ip");
var_dump($rsp);
$validation = json_decode($rsp, TRUE);
var_dump($validation);
if ($validation['success'] !== true) {
$errors[] = 'CAPTCHA failed. Please try again.';
}
}
var_dump($rsp)returns:
Local host:
string(91) "{ "success": false, "challenge_ts": "2016-02-27T17:08:05Z", "hostname": "localhost" }"
or
string(90) "{ "success": true, "challenge_ts": "2016-02-27T17:41:40Z", "hostname": "localhost" }"
Remote Server ALWAYS return:
bool(false)
var_dump($validation) returns:
Local Host:
array(3) { ["success"]=> bool(false) ["challenge_ts"]=> string(20) "2016-02-27T17:08:05Z" ["hostname"]=> string(9) "localhost" }
or
array(3) { ["success"]=> bool(true) ["challenge_ts"]=> string(20) "2016-02-27T17:41:40Z" ["hostname"]=> string(9) "localhost" }
Remote Server ALWAYS return:
NULL
I am NOT a programmer and have limited knowledge. Thank you in advance for your help!
Upvotes: 2
Views: 1823
Reputation: 113
I found the answer: allow_url_fopen wasn't enabled on my remote host php file! Thanks!
Upvotes: 4