从Google解析验证是错误的吗?

时间:2016-05-05 02:34:04

标签: recaptcha

我使用here中的脚本进行验证。

无论我点击表单上的重新验证码验证,都会绕过$result === FALSE条件。

所以我决定手动解析它:

如果失败,返回看起来像这样:

{
 "success":false,
 "error-codes":[
  "missing-input-response"
 ]
}

如果它的成功看起来很相似,但附加了一些额外的东西,但我的主要目标是字符串"success":true,

将脚本的这一部分直接放在$result变量下面:

$result_copy = $result;
// remove white spaces everywhere
$mod_res_copy = preg_replace('/\s+/', '', $result_copy);
$success_string = '"success":true';
if(strpos($mod_res_copy, $success_string) !== false) {
    $status = "ok";
}else {
    $status = "not-ok";
}
if ($status == "not-ok") {
    echo "Please complete the captcha to prevent spam.";
    exit;
}else {
    // trigger database insert of comment or whatever
}

我想知道的是,这是错的吗?这可以欺骗吗?我使用PHP作为服务器端脚本语言。

1 个答案:

答案 0 :(得分:0)

你正在做的工作比你需要的更多,要解析$result 它是JSON格式,所以这就是你所需要的:

$status = json_decode($result)->success ? 'ok' : 'not-ok';

相关问题