How does this checkbox recaptcha work and how can I use it?

后端 未结 5 740
情书的邮戳
情书的邮戳 2020-12-22 19:21

I\'ve recently signed up to the oneplusone website https://account.oneplus.net/sign-up, and noticed this checkbox recaptcha

How does it work, and how can I

5条回答
  •  庸人自扰
    2020-12-22 19:31

    Here is my code running without problem in PHP:

    Client Side:

    Server Side:

    if (isset($_POST['g-recaptcha-response'])) {
        $captcha = $_POST['g-recaptcha-response'];
        $privatekey = "SECRET_KEY";
        $url = 'https://www.google.com/recaptcha/api/siteverify';
        $data = array(
            'secret' => $privatekey,
            'response' => $captcha,
            'remoteip' => $_SERVER['REMOTE_ADDR']
        );
    
        $curlConfig = array(
            CURLOPT_URL => $url,
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS => $data
        );
    
        $ch = curl_init();
        curl_setopt_array($ch, $curlConfig);
        $response = curl_exec($ch);
        curl_close($ch);
    }
    
    $jsonResponse = json_decode($response);
    
    if ($jsonResponse->success == "true")
        doSomething();
    else
        doSomeOtherThing();
    

    :)

提交回复
热议问题