【发布时间】:2018-08-12 07:14:07
【问题描述】:
我在我的网站查询表中使用google recaptcha。我使用 cURL 而不是 file_get_contents(),因为我的服务器的 allow_url_fopen 由于安全问题而被禁用。这是我验证recaptcha的代码:
<?php
$response=htmlspecialchars($_POST["captcha"]);
$secret = "my_secret_key";
$curl = curl_init();
$captcha_verify_url = "https://www.google.com/recaptcha/api/siteverify";
curl_setopt($curl, CURLOPT_URL,$captcha_verify_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "secret=".$secret."&response=".$response);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$captcha_output = curl_exec ($curl);
curl_close ($curl);
$decoded_captcha = json_decode($captcha_output);
$captcha_status = $decoded_captcha['success']; // store validation result to a variable.
if($captcha_status === FALSE){
echo "fail";
}
else
{
echo "success";
}
?>
我的问题是当我检查 recaptcha 时,如果我将 google url 更改为任何内容或将我的密钥更改为任何内容,我都会得到响应成功。如果密钥不正确,它不应该返回成功吗?即使我更改了google_verify_url,我也会得到成功响应。我无法理解发生了什么。我这边有什么问题吗?
【问题讨论】: