0

We are looking to redirect users to different pages after code has been executed, eg. form validation, session timeouts etc..

Placing the following in the code:

header("Location: http://localhost/example/"); exit();

Appears to do nothing more than exit() the code being executed at the correct point. It does not redirect the page to that URL.

How do we physically redirect the page to another URL.

3
  • Do you have any output (echo, print, some HTML, ...) before the header call? Commented Jun 19, 2012 at 10:34
  • Are you getting any error? Have you error reporting on ? Commented Jun 19, 2012 at 10:34
  • 2
    Turn on the error reporting by calling error_reporting(true); and ini_set('display_errors',E_ALL); you should get some error messages may be "headers already sent" Commented Jun 19, 2012 at 10:36

2 Answers 2

1

You likely have whitespace in the output before the Header() function is called. The header cannot be called after ANY output is sent back to the browser.

If you can view the output of that file, you might see that there is some whitespace created by an include or something else in your script prior to the Header() being called.

If you cannot avoid output prior to that call, you might have to resort to a javascript to do the redirection. A JavaScript Window.Location should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

How about using the HTML Redirect after executing the necessary code?

echo '<meta http-equiv="Refresh" content="0;url=http://localhost/example/" />'

1 Comment

Using this you aren't addressing your actual problem, as Fluffeh suggests you are sending some output before the header. If you don't resolve this it will just manifest itself in future when you try to set some other header.

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.