Skip to content
Permalink
Browse files

Change reCAPTCHA to v3

  • Loading branch information
paizi committed Apr 15, 2019
1 parent 0c663ad commit 8ae054397dda37df6f2a5288b15c9e5b6e9735cb
Showing with 21 additions and 30 deletions.
  1. +21 −30 index.php
@@ -9,7 +9,15 @@
<style>
* {font-family: "微软雅黑"}
</style>
<script src='https://www.recaptcha.net/recaptcha/api.js'></script>
<script src="https://www.google.com/recaptcha/api.js?render=Your_Site_Key"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('Your_Site_Key', { action: 'verify' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
</script>
</head>
<body>
<div class="container">
@@ -28,40 +36,23 @@
<option value="nyaapost">Nyaacat 喵窝</option>
</select>
<br>

<span style="font-size:14px;"> <div class="g-recaptcha" data-sitekey="6LedJJ4UAAAAAHWasWnzTXZ1d_xPr-MmuwgW2bFW"></div></span>

<br>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</form>
<?php
function send_post($url, $post_data)
{
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}

$post_data = array(
'secret' => '6LedJJ4UAAAAAClNQIGXrCmzGvil09EU6sRMZ9X4',
'response' => $_POST["g-recaptcha-response"] );
$recaptcha_json_result = send_post('https://www.recaptcha.net/recaptcha/api/siteverify', $post_data);
$recaptcha_result = json_decode($recaptcha_json_result,true);
?>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['recaptcha_response'])) {
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = 'Your_Site_Key';
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha);
} ?>

<?php
if(!empty($_POST["post"])){
if(!empty(json_decode($recaptcha_result['success'])))
if ($recaptcha->score >= 0.6)
{
if(!empty($_POST["select"]) && !empty($_POST["post"])){
$mcapiurl="https://api.mojang.com/users/profiles/minecraft/".$_POST["post"];
@@ -82,7 +73,7 @@ function send_post($url, $post_data)
$ban=json_decode($dkjson['data']['banned']);}
else { $ban="notpass"; echo '<div class="alert alert-danger alert-dismissible fade show">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>等等!</strong>请确认您不是机器人</div>';}}
<strong>等等!</strong>reCAPTCHA认为您是机器人。如果您不是的话,<a href="rev2.php">请点击这里</a></div>';}}
?>
</div>

0 comments on commit 8ae0543

Please sign in to comment.
You can’t perform that action at this time.