Jump to content

[SOLVED] reCaptcha - redirected landing page upon failure


gckmac

Recommended Posts

Cannot get reCaptcha to redirect to a failure landing page.  I am testing this at www.maine.info/form1.php ... which correctly goes to www.maine.info/form2.php

 

The entire code on form2.php is below.  The code within that section that fails to work (though suggested by many) is:

 

if(!$resp->is_valid) {

header("location:apartments.php");

die();

}

 

The header thing does not work.  Cannot get an error landing page to be invoked.

 

THIS IS THE FULL PAGE CODE BELOW:

 

<?php

require_once("captcha/recaptchalib.php");

$privatekey = "xxxxx";

$resp = recaptcha_check_answer ($privatekey,

                              $_SERVER["REMOTE_ADDR"],

                              $_POST["recaptcha_challenge_field"],

                              $_POST["recaptcha_response_field"]);

 

 

#if (!$resp->is_valid) {

#  // What happens when the CAPTCHA was entered incorrectly

#  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .

#      "(reCAPTCHA said: " . $resp->error . ")");

 

 

if(!$resp->is_valid) {

header("location:apartments.php");

die();

 

 

 

 

} else {

  // Your code here to handle a successful verification

}

?>

 

<p><font face="arial">

Hi <?php echo htmlspecialchars($_POST['name']); ?>.

You are <?php echo (int)$_POST['age']; ?> years old.</p></font>

 

 

Thanks for your advice!

gckmac

 

 

Solved it by using javascript instead of header() function.  Code that works is as follows:

 

<?php

require_once("captcha/recaptchalib.php");

$privatekey = "6Le_LAYAAAAAAMAbcuBVpmqrrs0vN3alYZSYVt75";

$resp = recaptcha_check_answer ($privatekey,

                              $_SERVER["REMOTE_ADDR"],

                              $_POST["recaptcha_challenge_field"],

                              $_POST["recaptcha_response_field"]);

#if (!$resp->is_valid) {

#  // What happens when the CAPTCHA was entered incorrectly

#  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .

#      "(reCAPTCHA said: " . $resp->error . ")");

if(!$resp->is_valid) {

?>

<script>

window.location.href='http://www.maine.info/apartments';

</script>

<?php

} else {

  // Your code here to handle a successful verification

}

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.