0
我試圖實施谷歌recaptcha v2。我有兩個小例子文件:recaptcha.html和recaptcha.phprecaptcha v2顯式渲染基本設置:無效輸入響應
recaptcha.html:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script>
var showRecaptcha = function() {
Recaptcha.create("6LfCLRQTAAAAAFyZ4QZ6mMl7bu2syW9yH813kHnG",
'captchadiv',
{
size: "compact",
callback: Recaptcha.focus_response_field
}
);
}
</script>
<script src="https://www.google.com/recaptcha/api.js?onload=showRecaptcha&render=explicit"
async defer>
</script>
</head>
<body>
<form id="rmForm" role="form" action="recaptcha.php"
method="post" accept-charset="utf-8" enctype="multipart/form-data" >
<div id="captchadiv"></div>
</form>
</body>
</html>
和recaptcha.php:
<?php
$secret = "6LfCLRQTAAAAABgzTkyDJMxEo-HTnEEr8xBEv1wE";
if(isset($_REQUEST["recaptcha_response_field"])) {
// we are processing a remove request with a recaptcha
$captcha=$_REQUEST["recaptcha_response_field"];
var_dump($captcha);
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?" .
"secret=$secret&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
}
if($response.'success'==true) { echo '<h2>Thanks for posting comment.</h2>'; }
var_dump($response);
?>
這也可在http://gps-photo.com/recaptcha.html。如你所見,如果你嘗試它,它總會給出'無效輸入響應'。在我看來,它應該工作,所以我顯然感到困惑。
有人可以幫忙嗎?謝謝。