perficut Posted June 22, 2008 Share Posted June 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 22, 2008 Share Posted June 22, 2008 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
perficut Posted June 22, 2008 Author Share Posted June 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
Darklink Posted June 22, 2008 Share Posted June 22, 2008 It's not the proper way to solve all your header problems, but put ob_start(); at the top of the page. Quote Link to comment Share on other sites More sharing options...
perficut Posted June 22, 2008 Author Share Posted June 22, 2008 Still doesnt want to work. I put ob_start(); at the beginning. Tried using the header() function that didnt work, then went back to a variable assigned with the url. That didnt work. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
Darklink Posted June 22, 2008 Share Posted June 22, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
perficut Posted June 22, 2008 Author Share Posted June 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
Darklink Posted June 22, 2008 Share Posted June 22, 2008 Hmm. Try using another method of redirection? Header may not be the best choice because the script before it may include some output values (cookies, etc). Try to make a template or page which redirects using a meta redirection or javascript. Quote Link to comment Share on other sites More sharing options...
perficut Posted June 22, 2008 Author Share Posted June 22, 2008 Thanks Darklink, I was able to get the javascript to work. Now I think I will be able to incorporate this code into my form and hopefuly get it all to work together. thank you. Quote Link to comment Share on other sites More sharing options...
Darklink Posted June 22, 2008 Share Posted June 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted June 22, 2008 Share Posted June 22, 2008 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? Quote Link to comment Share on other sites More sharing options...
Darklink Posted June 22, 2008 Share Posted June 22, 2008 Well sites I make normally require a user to have JavaScript enabled (otherwise they are outdated and annoying). I would advise using the meta redirection. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.