rAthus icon

reCAPTCHA v2

rAthus | PRO | 10/27/15 04:01:22 PM UTC | 0 ⭐ | 866 👁️ | Never ⏰ | []
PHP |

960 B

|

None

|

0 👍

/

0 👎

// URL pour générer des clés: https://www.google.com/recaptcha/admin
 
// Affichage du bouton :
// <script src='https://www.google.com/recaptcha/api.js'></script>
// <div class="g-recaptcha" data-sitekey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></div>
 
// Vérification :
$recaptcha_ok = -1;
if (!empty($_REQUEST['g-recaptcha-response']))
{
    $recaptcha_ok = 0;
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $myvars = 'secret=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY&response='.htmlspecialchars($_POST['g-recaptcha-response'],ENT_QUOTES);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    $json = json_decode($response);
    if ($json->success)
        $recaptcha_ok = 1;
}
 
// Si le reCAPTCHA est validé, alors $recaptcha_ok = 1;

Comments