Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $resp = $_POST['g-recaptcha-response'];
- $userIp = $_SERVER['REMOTE_ADDR'];
- $secretKey = 'YOUR_PRIVATE_KEY';
- $recaptchaUrl = 'https://www.google.com/recaptcha/api/siteverify'
- . '?secret=' . $secretKey
- . '&response=' . $resp
- . '&remoteip=' . $userIp;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $recaptchaUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $json = curl_exec($ch);
- curl_close($ch);
- if (!$json) {
- // TODO: Throw error due to the server (HTTP 5xx)
- } else {
- $arr = json_decode($json, true);
- if(!$arr['success']) {
- // TODO: User identified as a machine, display an error on the form page
- } else {
- // TODO: User identified as a human, continue processing...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement