当我检查 reCaptcha 服务器端时发出警告
Warning when I check the reCaptcha server side
我在服务器端检查 reCAPTCHA 时收到警告。
这是我的错误:
我理解"invalid-input-secret"因为我在上面的url中使用了"mysecretkey"。问题是"invalid-input-response"。
我在下面粘贴我的代码。
$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";
}
感谢您的帮助。
也许您的 php.ini
中的 allow_url_fopen = Off
阻止了 file_get_contents
打开 URL。
您可以为此使用 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);
添加
$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 */
}
我在服务器端检查 reCAPTCHA 时收到警告。 这是我的错误:
我理解"invalid-input-secret"因为我在上面的url中使用了"mysecretkey"。问题是"invalid-input-response"。 我在下面粘贴我的代码。
$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";
}
感谢您的帮助。
也许您的 php.ini
中的 allow_url_fopen = Off
阻止了 file_get_contents
打开 URL。
您可以为此使用 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);
添加
$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 */
}