reCAPTCHA在localhost上工作但不在REMOTE服务器

时间:2016-02-27 17:47:31

标签: php recaptcha

我在将reCAPTCHA添加到我的网站时遇到了一些问题。下面的代码在我的本地主机上正常工作,但在远程服务器上却没有。

    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)返回:

本地主持人:

string(91) "{ "success": false, "challenge_ts": "2016-02-27T17:08:05Z", "hostname": "localhost" }" 

string(90) "{ "success": true, "challenge_ts": "2016-02-27T17:41:40Z", "hostname": "localhost" }"

远程服务器总是返回:

bool(false) 

var_dump($ validation)返回:

本地主持人:

array(3) { ["success"]=> bool(false) ["challenge_ts"]=> string(20) "2016-02-27T17:08:05Z" ["hostname"]=> string(9) "localhost" } 

array(3) { ["success"]=> bool(true) ["challenge_ts"]=> string(20) "2016-02-27T17:41:40Z" ["hostname"]=> string(9) "localhost" } 

远程服务器总是返回:

NULL

我不是程序员,知识有限。 提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我找到了答案: 我的远程主机php文件上没有启用allow_url_fopen! 谢谢!