我理解"无效输入秘密"因为我使用过" mysecretkey"在上面的网址中。问题是"无效输入 - 响应"。 我在下面粘贴我的代码。
$secretKey = "mysecretkey";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$_POST["g-recaptcha-response"]."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1)
{
echo "you're a robot";
} else {
echo "form's control";
}
感谢您的帮助。
答案 0 :(得分:0)
也许allow_url_fopen = Off
中的php.ini
阻止了file_get_contents
打开网址。
您可以使用cURL,如下所示:
$fields = array(
'secret' => "MySecretKey",
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$ch = curl_init("https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = json_decode(curl_exec($ch));
curl_close($ch);
答案 1 :(得分:-1)
添加
$secretKey = "mysecretkey";
$captcha = $_POST["g-recaptcha-response"]; //Add This Line
尝试:
$url="https://www.google.com/recaptcha/api/siteverify?secret={$secretkey}&response={$captcha}&remoteip={$ip}";
$options = array(
'secret' => "MySecretKey",
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$context = stream_context_create( $options );
$responseKeys=json_decode( file_get_contents( $url, FILE_TEXT, $context ) );
if( $responseKeys->success ){
/* everything is ok */
}
else{
/* captcha failed */
}