Last active
January 10, 2018 16:58
-
-
Save nfreear/8f74ab520daf8e42b289b04af9aa4f87 to your computer and use it in GitHub Desktop.
reCAPTCHA PHP test — https://developers.google.com/recaptcha
This file contains 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 | |
/** | |
* reCAPTCHA test. | |
* | |
* @copyright Nick Freear / 09-January-2018. | |
* @link https://gist.github.com/nfreear/8f74ab520daf8e42b289b04af9aa4f87 | |
* | |
* USAGE: php -S localhost:8000 recaptcha-test.php | |
*/ | |
define( 'RECAP_SITE_KEY', '6Ld-JBUUAAAAAMHvznBQrBJIH0M3hObGrZPsgaOK' ); | |
define( 'RECAP_SECRET', 'XXX' ); // Developer account !! | |
define( 'RECAP_URL', 'https://www.google.com/recaptcha/api/siteverify' ); | |
define( 'RECAP_RESPONSE', filter_input( INPUT_POST, 'g-recaptcha-response' )); | |
define( 'LANG', filter_input( INPUT_GET, 'lang' )); | |
define( 'POST_REQUEST', $_SERVER[ 'REQUEST_METHOD' ] === 'POST' ); | |
define( 'HTTP_PROXY', 'wwwcache.open.ac.uk:80' ); // Must be without a "http://" !! | |
if (POST_REQUEST) { | |
$server_response = file_get_contents( RECAP_URL, false, httpPostContext([ | |
'secret' => RECAP_SECRET, | |
'response' => RECAP_RESPONSE, | |
// 'remoteip' => ? | |
]) ); | |
var_dump( $server_response, RECAP_RESPONSE, $http_response_header ); | |
} | |
?><!doctype html><html><title> *reCAPTCHA test </title> <h1> reCAPTCHA test </h1> | |
<form action="?lang=<?= LANG ?>" method="POST"> | |
<p><div class="g-recaptcha" data-sitekey="<?= RECAP_SITE_KEY ?>"></div> | |
<p><input type="submit" /> | |
</form> | |
<script src="https://www.google.com/recaptcha/api.js?hl=<?= LANG ?>" async defer ></script> | |
</html> | |
<?php function httpPostContext($postdata) { | |
$postdata = is_array( $postdata ) ? http_build_query( $postdata ) : $postdata; | |
return stream_context_create([ | |
'http' => [ | |
'method' => 'POST', | |
'user_agent' => 'CloudEngine/1.0-beta +https://github.com/nfreear', | |
'proxy' => HTTP_PROXY, | |
'header' => [ | |
'Content-Type: application/x-www-form-urlencoded', | |
'Content-Length: ' . strlen( $postdata ), | |
], | |
'content' => $postdata, | |
'timeout' => 5, // Seconds. | |
] | |
]); | |
} | |
# End. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment