docker-vulnerable-dvwa/dvwa/external/recaptcha/recaptchalib.php

46 lines
969 B
PHP
Raw Normal View History

2016-12-02 19:19:11 +00:00
<?php
2018-10-12 15:49:58 +00:00
// new php7 captcha v2 implementation.
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
function recaptcha_check_answer($key, $response){
return CheckCaptcha($key, $response);
2016-12-02 19:19:11 +00:00
}
2018-10-12 15:49:58 +00:00
function CheckCaptcha($key, $response) {
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
try {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$dat = array(
'secret' => $key,
'response' => urlencode($response),
'remoteip' => urlencode($_SERVER['REMOTE_ADDR'])
);
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
$opt = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($dat)
)
);
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
$context = stream_context_create($opt);
$result = file_get_contents($url, false, $context);
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
return json_decode($result)->success;
2016-12-02 19:19:11 +00:00
2018-10-12 15:49:58 +00:00
} catch (Exception $e) {
return null;
2016-12-02 19:19:11 +00:00
}
}
2018-10-12 15:49:58 +00:00
function recaptcha_get_html($pubKey){
return "
<script src='https://www.google.com/recaptcha/api.js'></script>
<br /> <div class='g-recaptcha' data-theme='dark' data-sitekey='" . $pubKey . "'></div>
";
2016-12-02 19:19:11 +00:00
}
?>