我想在我的Web服务中使用recaptcha。 我添加
.g-recaptcha(data-sitekey='mysitekey')
并像这样制作javascript
if (typeof(grecaptcha) != 'undefined'){
if (grecaptcha.getResponse() == ""){
alert("error")
return;
}
}
$(function chk_recaptcha(){
if (!isset($_POST['g-recaptcha-response']))return false;
$gg_response = trim($_POST['g-recaptcha-response']);
if ($gg_response == "") return false;
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array('secret' = 'mysecret key',
'response' = $gg_response,
'remoteip' = $_SERVER['REMOTE_ADDR']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, sizeof($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_closr($ch);
$obj = json_decode($result);
if ($obj = success ==false){
alert("error!");
history.go(-1);
}
return true;
});
但是当我忽略检查Recaptcha时, 仍然会继续进行,而不会发出警报。
我该如何解决这个问题?