0

I have the following tag for when a user is successfully logged in:

header('Location: /members');

It always used to work. Now, however, when I try to load the page, Chrome gives me this error:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

On Firefox, I just get a blank page. When I comment the header statement out, it works, but without the redirect (obviously).

I have tried it with output buffering on and off, with the same effect. Any ideas?

Edit: I have a PHP header statement at the beginning of the code that redirects users to the member page if they are already logged in. Could this be affecting it? I'm not getting any headers already sent errors...

3
  • Can you post all of the code around the header call? Commented Oct 22, 2011 at 6:36
  • 4
    Enable error_reporting or look into the error.log Commented Oct 22, 2011 at 6:36
  • 3
    Tip: always use exit() just after header() and write ob_start() at the top of the page Commented Oct 22, 2011 at 6:39

2 Answers 2

1

Just put error_reporting(E_ALL) and ini_set("display_errors", 1) and you'll see what's wrong.

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

Comments

0

Install the HTTP extension and use this instead:

http_redirect('/members');

This should do the trick. If you don't have it installed. you can mimic what it does. It's explained in detail on the manual page, the steps in short:

  • Create an absolute URI from the relative URI as redirects by RFC must have one.
  • Check if headers have already been send, if so don't send header, otherwise do.
  • Display a HTTP response body with the link of the redirect.
  • Exit the script.

If you don't follow the specs, you can not expect that things work with a browser. Many examples given in the internet are not giving conform redirects, so don't be misguided by bad examples.

Next to that - as already suggested by others - turn on error reporting on your development box so you are aware of any notices and warnings that your code produces. Deal with those issues as well.

1 Comment

The thing is, it was working fine before. I have turned on error reporting, but I get an error from Chrome, so I can't actually see the page. Also, there is nothing in the error log.

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.