Jump to content

Recommended Posts

I am trying to incorporate a captcha into one of my forms.  However, I keep running into the same problems. Once the captcha verifies the data input, I cant get it to then proceed to the "thankyou.htm" page.  In my searches everything points to using the header() function but I cant seem to get it to work. Keeps telling me header already sent.    I am sure this is probably and easy fix but since Im more of a binner, i cant seem to look through the code to find what could be the cause, or what the solution is. 

 

For simplicity sakes, I have posted the entire the source of the working example. If I can get it to work here then I can get it to work in my form. 

 

<html>
  <body>
    <form action="" method="post">
<?php

require_once('../recaptcha/recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LdhQAIAAAAAADD0DAmQYiLV-blwLkxhykzay2us ";
$privatekey = "6LdhQAIAAAAAAEELsaFefmf4y-C0KbyzU3Qj37Xw ";

# 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: http://www.google.com');
        } 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>
  </body>
</html>

 

 

The line header('Location: http://www.google.com');  as you already know, this is where you tell the source what to do if the captcha is correct.  If I echo something that will work. But this header function wont.  Any help you can give is greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/111332-header-issue/
Share on other sites

Thanks.  I just read it and tried to make the changes pointed out therein.  No luck.

 

I created a variable  $gohere = "http://www.thankyou.htm"; 

 

then put the variable in place of the header.  followed by and exit

 

the program only halts and does not send you to the thankyou page.

 

Link to comment
https://forums.phpfreaks.com/topic/111332-header-issue/#findComment-571514
Share on other sites

<?php

require_once('../recaptcha/recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6LdhQAIAAAAAADD0DAmQYiLV-blwLkxhykzay2us ";
$privatekey = "6LdhQAIAAAAAAEELsaFefmf4y-C0KbyzU3Qj37Xw ";

# 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) {
                $redirect = true;
                header('Location: http://www.google.com');
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}

if ( !$redirect )
{
       echo recaptcha_get_html($publickey, $error);
}
?>

 

Could be something with reCaptcha though. What was your error exactly.

Link to comment
https://forums.phpfreaks.com/topic/111332-header-issue/#findComment-571524
Share on other sites

I have tried a couple different captcha applications, they all lead me to the same results.  In the example.php files included in the zip file, they always echo"YOU GOT IT", or "THAT IS CORRECT".  Of course in my application I want it to not echo but rather send them to the thankyou page.  When I try to make this change I always get a header problem.

 

heres the message for the above source

 

 

Warning: Cannot modify header information - headers already sent by (output started at /home/perficut/public_html/recaptcha/example-captcha.php:4) in /home/perficut/public_html/recaptcha/example-captcha.php on line 25

 

 

Link to comment
https://forums.phpfreaks.com/topic/111332-header-issue/#findComment-571526
Share on other sites

Glad I could help.

 

Personally I hardly ever use header() to relocate but I suppose it has it's purposes in some areas.

For redirection I use javascript with a nice redirection page. It can let the user know where they are going too. :)

 

so what happens if they turn off javascript?

Link to comment
https://forums.phpfreaks.com/topic/111332-header-issue/#findComment-571566
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.