Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1238
  • Last Modified:

Redirecting to a page after reCaptcha is correct!

I have a reCaptcha page I'm adding to my site.  I have incorporated the reCaptcha code, however, I would like to make it so that once the page is verified the user would be sent to a new page.  I thought it would be easy to use the:
header('Location: /x/type.php');
exit;

Open in new window


however, this does not work (it gives a header already sent error).  Can someone point me in the right direction with this one.

Thanks,

jbrich01
<script type = "text/javascript">
    var RecaptchaOptions = {
       theme : 'white'
    };
    </script>
<form action="" method="post">
 <script type = "text/javascript">
    var RecaptchaOptions = {
       theme : 'white'
    };
    </script>
	<?php

require_once('recaptchalib.php');


// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "OMITTED";
$privatekey = "OMITTED2";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
			header('Location: /x/type.php');
			exit;
		
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
				
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" value="submit" />
    </form>

Open in new window

0
jbrich01
Asked:
jbrich01
  • 5
  • 3
  • 2
2 Solutions
 
edster9999Commented:
in your php config file set it to use php buffering and then it will hold back until the headers get sent and that redirection will work
0
 
edster9999Commented:
$ locate php.ini

/etc/apache2/php/php.ini

$ vi /etc/apache2/php/php.ini

find the line that says :

output_buffering = off

and set it to on

restart apache and that should re-read that file in php.
0
 
Ray PaseurCommented:
Put the reCaptcha form on the page you want to test.  Put the reCaptcha evaluation on the action script page.  It's just that easy - no special redirects or anything like that.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jbrich01Author Commented:
Hi Edster 9999,

I will try that and let you know if it works.  Thanks.
_________________________________________________________________
Hi Ray Paseur,
I tried that, but it did not work for me.  Maybe i put in some extraneous code.  I will give it another try.

Thanks.

jbrich01
0
 
Ray PaseurCommented:
You might also try adding this line to the top of your scripts:

ob_start();

That will turn on the output buffers.  

But I do not think output buffering is the issue.  I think there is a logic flaw.  Instead of redirecting to /x/type.php, why not just do the processing right there inside the script that just performed the recaptcha verification?  I think that is how the pros would do it.

;-)

~Ray
0
 
jbrich01Author Commented:
Sorry guys, stuck at work for the last few days.  Neither suggestion worked.  Below is the orginal recapture code. The comment line that reads

// Your code here to handle a successful verification

is where I need help.

<?php   require_once('recaptchalib.php');   $privatekey = "your_private_key";   $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 . ")");   } else {     // Your code here to handle a successful verification   }   ?>

Open in new window

0
 
jbrich01Author Commented:
<?php   require_once('recaptchalib.php');   $privatekey = "your_private_key";   $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 . ")");   } else {     // Your code here to handle a successful verification   }   ?>
0
 
Ray PaseurCommented:
Please use the code snippet to post the code - it will be much easier for us to read, and we will have line numbers that facilitate communication.  Thanks.
0
 
jbrich01Author Commented:
Thanks guys, I solved it.  The problem was a white space issue in the template that I attached to the reCaptra page.
0
 
jbrich01Author Commented:
The solution turned out to be a white space issue in the template that I was using.  Not the reCaptra code or the redirect header('Location:') line.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now