Created
February 3, 2017 12:28
-
-
Save marcosnakamine/14bf22a68dc40158c341ec47962cead6 to your computer and use it in GitHub Desktop.
PHP - Google Recaptcha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( isset( $_POST['g-recaptcha-response'] ) ) { | |
// ENVIA INFORMAÇÕES POR POST PARA TESTAR O CAPTCHA | |
$result = file_get_contents( 'https://www.google.com/recaptcha/api/siteverify', false, stream_context_create( array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query( array( | |
'response' => $_POST['g-recaptcha-response'], | |
'secret' => '6LfrOwcTAAAqwAAPLs7mGIKHlBw4qwfcKTJR9tVY_g-Dr' | |
) ), | |
), | |
) ) ); | |
$result = json_decode( preg_replace("/\n|\r| /", "", $result ) ); | |
if ( $result->success ) { | |
// COLOQUE AQUI AS FUNÇÕES DO PHPMAILER | |
} | |
} | |
?> | |
<form method="post"> | |
<input type="text"> | |
<div class="g-recaptcha" data-sitekey="6LfrOwcTAqwgAAAAAGiqET2vLM2h84QdqwgC1w8hj0WyuB"></div> | |
<script type="text/javascript" | |
src="https://www.google.com/recaptcha/api.js?hl=pt-BR"> | |
</script> | |
<button>enviar</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment