ReCaptcha一直在说我是机器人,永远不会成功吗? [英] ReCaptcha keeps saying im a bot, doesn't ever succeed?
本文介绍了ReCaptcha一直在说我是机器人,永远不会成功吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网站上使用的是旧版本的ReCaptcha,但是我只是升级到了新的ReCaptcha,我有3-4种不同的教程,但是它总是会失败并给出失败错误.
I was using the old ReCaptcha on my site but just upgrading to the new ReCaptcha i've 3-4 different tutorials but it keeps failing and giving the fail error.
HTML
<form method="POST" action="/feedback_sent/" enctype="multipart/form-data">
<table border="0" width="100%" cellpadding="4" cellspacing="4" height="67">
<tr>
<td width="30%" height="30">Name</td>
<td width="70%" height="30">
<p><input type="text" name="name" size="41"></p>
</td>
</tr>
<tr>
<td valign="top" width="30%" height="27">Feedback</td>
<td width="70%" height="27">
<textarea rows="8" name="feedback" cols="57"></textarea></td>
</tr>
<tr>
<td valign="top" width="30%" height="27"></td>
<td width="70%" height="27">
<div class="g-recaptcha" data-sitekey="My_Key"></div>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<p align="center"><input type="submit" value="Submit" name="B1"></td>
</tr>
</table>
</form>
PHP:
$secret="---my key---";
$response=$_POST["g-recaptcha-response"];
$verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
}
else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
推荐答案
步骤1:
您将需要在此处创建一个公共密钥和私有密钥.
Step 1:
You will need to create a public and a private key here.
包含此库以处理服务器上的信息.
Include this library to process the information on the server.
<?php
$public = "yourkey";
$private = "yourkey";
$lang = "en";
if(isset($_POST['submit'])){
if(array_key_exists('g-recaptcha-response', $_POST)){
require 'path/to/recaptcha/autoload.php';
$c = new ReCaptcha\ReCaptcha($private);
$r = $c->verify(
$_POST["g-recaptcha-response"],
$_SERVER["REMOTE_ADDR"]
);
if($r->isSuccess()){
echo 'success';
} else {
echo 'failed';
}
} else {
die('client failure, enable js or update browser');
}
} else {
die('form failure');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>ReCaptcha 2.0</title>
</head>
<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<input for="email" name="email" type="email" required>
<input for="password" name="password" type="password" required>
<div class="g-recaptcha" data-sitekey="<?= $public ?>"></div>
<input type="submit" name="submit" value="Submit">
</form>
<script src='https://www.google.com/recaptcha/api.js?hl=<?= $lang ?>'></script>
</body>
</html>
根据输入内容,将显示success
或failed
.
This will say either success
or failed
depending on the input.
这篇关于ReCaptcha一直在说我是机器人,永远不会成功吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文