2

How in a PHP script do I redirect to another page? I tried header, but this didn't work since before my header() statement is an echo.

This, I do not want to use:

echo "<meta http-equiv='refresh' content='1;URL=?".$link."'>"; 
1
  • 1
    Why would you want to do an echo if you redirect the user anyway? You could just put the header() at the very beginning. Commented Jul 2, 2010 at 6:34

2 Answers 2

6
  • Use ob_start() to delay the printing, and use header(), or
  • Redirect using Javascript, this can be done anywhere in the page, or
  • Rewrite your code so that you know early on, before anything is printed, whether you want a redirect.
Sign up to request clarification or add additional context in comments.

Comments

2

You would want to do the following:

header('Location: http://www.someURL.com');

But this must be done before anything is dropped to the output steam. Also you would not want to use

echo "<meta http-equiv='refresh' content='1;URL=?".$link."'>"; 

As it would force the browser to reload your page, effectively rendering it useless if the user is trying to click a link or type something just as it refreshes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.