Answer the question
In order to leave comments, you need to log in
RECAPTCHA, AJAX and MVC - In order not to generate a new captcha every time the controller is accessed, we save it to the session. But what if the time is up?
Hello! I have a captcha in the article edit.
To save the changes, you need to solve the captcha. If the captcha is not solved, then the server issues an error message via AJAX.
Let's imagine that the user solved the captcha. Sent the changes to the server. Validation passed, changes saved. Everything is great.
But then the user saw that he forgot to put a comma here and there. He puts it and again sends the form to the server. In the controller, the form is validated and... CAPTCHA. The problem is that when checking a new captcha is created:
$response = null;
$reCaptcha = new ReCaptcha(self::SECRET_KEY);
if ($value) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$value
);
}
if ($response != null && $response->success) {
return true;
}
static public function captcha_is_true($value, $validation) {
// Заблоговременный результат
if (!$value) {
return $validation->error(self::FUNCTION_NAME, null);
}
$captcha_is_true = Session::instance()->get(self::SESSION_NAME);
if ($captcha_is_true) {
return true; // НО ЭТО ВЕДЬ НЕ РАЗГАДКА КАПЧИ?
}
// Вычисляемый результат
$response = null;
$reCaptcha = new ReCaptcha(self::SECRET_KEY);
if ($value) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$value
);
}
if ($response != null && $response->success) {
Session::instance()->set(self::SESSION_NAME, true);
return true;
} else {
return $validation->error(self::FUNCTION_NAME, null);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question