spryce Posted January 13, 2011 Share Posted January 13, 2011 Newbie question. I have a form that uses reCaptcha. If the Captcha is entered correctly it posts the data. Can I redirect the page using php or do I need to use javascript? I was going to throw in header('Location: thankyou.php'); but from my limited understanding this cannot be used anywhere except the very top of the page. 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 { echo "Recapture entered correctly!"; // Just for testing purposes postdata($firstname, $lastname, $company, $email, $phone, $comments); // sends data to my databse // this is where I would expect to redirect to a new page } Thanks phpfreaks Quote Link to comment https://forums.phpfreaks.com/topic/224272-can-a-redirect-to-a-local-page-from-within-a-function/ Share on other sites More sharing options...
spryce Posted January 13, 2011 Author Share Posted January 13, 2011 PS - i did read the sticky on header errors. I have a stack of $POST calls ie $subject = check_input($_POST['subject']); before my function. I assume this means that data is sent to the browser which is why I cant use the header function. But the reCaptcha stuff doesnt work unless this comes first. Quote Link to comment https://forums.phpfreaks.com/topic/224272-can-a-redirect-to-a-local-page-from-within-a-function/#findComment-1158725 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 If echo "Recapture entered correctly!"; isn't commented out, the redirect surely won't work after it. Other than that, it's impossible to tell without the rest of the preceding code. Also, whenever you use a header() redirect, you should immediately follow it with an exit(); to stop the further execution of code in the script. Quote Link to comment https://forums.phpfreaks.com/topic/224272-can-a-redirect-to-a-local-page-from-within-a-function/#findComment-1158750 Share on other sites More sharing options...
.josh Posted January 13, 2011 Share Posted January 13, 2011 $subject = check_input($_POST['subject']); You can have a header() call after that... $_POST is a global array of data the user submitted to the script. You can have a header() call anywhere in your script, as long as there is no output before it (and even then you can, though it's not recommended) Quote Link to comment https://forums.phpfreaks.com/topic/224272-can-a-redirect-to-a-local-page-from-within-a-function/#findComment-1158754 Share on other sites More sharing options...
spryce Posted January 13, 2011 Author Share Posted January 13, 2011 Thanks for the very informative responses guys. Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/224272-can-a-redirect-to-a-local-page-from-within-a-function/#findComment-1158812 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.