简体   繁体   中英

reCAPTCHA working on localhost but not on REMOTE server

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!

I found the answer: allow_url_fopen wasn't enabled on my remote host php file! Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM