ReCAPTCHA: why can't I double check the same result?

I mean, if I check the input of the first clients, and this is normal, the second check of the same input is always false ... Why is this?

I really need to check it twice (one for client side verification and one for server side verification)

Thanks in advance!

EDIT

Clarification:

If user input is OK and recaptcha returns true (I do it via ajax on my server, which sends a request to the recaptcha server), the form sends and sends through POST also 2 variables: recaptcha_challenge_field value and recaptcha_response_field value (<which has already been checked), and my server asks the recaptcha server to check these two values ​​again for server side validation.

JQuery code:

 $("#form_id").find("button").click(function(){ var c = $("#recaptcha_challenge_field").val(), r = $("#recaptcha_response_field").val(); $.ajax({ url: "/ajax/captcha?challenge=" + c + "&response=" + r, dataType: "json", success: function(data){ if(data['is_valid']){ $.ajax({ url: "/ajax/captcha?challenge=" + c + "&response=" + r, dataType: "json", success: function(data){ if(data['is_valid']){ alert('OK'); }else{ alert('FAILED'); } } }); }else{ Recaptcha.reload(); } } }); return false; }); 

So, as you can see, there are two absolutely identical operations with a different result (it only alerts FAILED ).

+8
captcha recaptcha
source share
2 answers

Because it is stored in a session, which is cleared when the result is sent. When the page loads, a new session variable is created for this CAPTCHA value.

+6
source share

For checking Captcha twice through AJAX / Jquery and on the server page this is my method with PHP (the main idea is to restore Captcha Session Variables cleared by the Captcha Check method if the error introduced with the client-side check is fixed, so they will be there again for server side verification):

  • The following may seem confusing as this is one of my lazy ways to reuse client-side validation on both an HTML form and an action page in an HTML form.

  • In the HTML form, add an additional POST variable (for example, $ _POST ["task"] = "validate", which is not an input element in the form that will be submitted when the form is submitted for client-side validation. PHP page

     $.ajax({ type: "POST", url: "registration_validate.php", data: ({ task:"validate" << and other data >> 
  • On the client side PHP validation page

     $securimage_session_cv = $_SESSION["securimage_code_value"]["default"]; $securimage_session_ct = $_SESSION["securimage_code_ctime"]["default"]; if ($securimage->check($_POST['captcha_code']) == false) { // return false or print something } else { // if this script is called via ajax for form validation if(isset($_POST['task']) && trim($_POST['task']) == "validate"){ // captcha will be cleared if valid/correct, restore them as it will be validated again on server side script $_SESSION["securimage_code_value"]["default"] = $securimage_session_cv; $_SESSION["securimage_code_ctime"]["default"] = $securimage_session_ct; } } 
  • On the server side validation page or the URL of the form form, you will have an unfinished Captcha session to validate.

+2
source share

All Articles