Skip to content

Instantly share code, notes, and snippets.

@dimisdas
Created March 3, 2018 20:32
Show Gist options
  • Save dimisdas/e660ebdfd3c43a3f6c69acc4f29321c4 to your computer and use it in GitHub Desktop.
Save dimisdas/e660ebdfd3c43a3f6c69acc4f29321c4 to your computer and use it in GitHub Desktop.
$post_data = http_build_query(
array(
'secret' => CAPTCHA_SECRET,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $post_data
)
);
$context = stream_context_create($opts);
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
$result = json_decode($response);
if (!$result->success) {
throw new Exception('Failed to verify CAPTCHA', 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment