Jump to content

can a redirect to a local page from within a function?


spryce

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.  :(

Link to comment
Share on other sites

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.

Link to comment
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.