gckmac Posted April 29, 2009 Share Posted April 29, 2009 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 Link to comment https://forums.phpfreaks.com/topic/156164-solved-recaptcha-redirected-landing-page-upon-failure/ Share on other sites More sharing options...
gckmac Posted April 29, 2009 Author Share Posted April 29, 2009 I have also tried the following to no avail: if(!$resp->is_valid) { header("Location: http://www.maine.info/apartments.php"); exit; It is as if the header() function does not work. gckmac Link to comment https://forums.phpfreaks.com/topic/156164-solved-recaptcha-redirected-landing-page-upon-failure/#findComment-822184 Share on other sites More sharing options...
gckmac Posted April 29, 2009 Author Share Posted April 29, 2009 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 } ?> Link to comment https://forums.phpfreaks.com/topic/156164-solved-recaptcha-redirected-landing-page-upon-failure/#findComment-822189 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.