views:

40

answers:

2

I cannot figure out what could be causing this error. My Apache log is not recording any errors in the access log or error log regarding the page, yet somehow whenever I uncomment the header() line I get a 500 Internal Server Error. It can't be coming from PHP's fatal error when content is outputted before header() is called, that wouldn't cause a 500 would it?

header("Location: /offices/page-".ceil($cache->size() / 15));

I tested $cache->size() and it's returning 22, so it should append a 2 to the end of the string and redirect. I did have ob_start() called before the header() but I tried calling ob_end_clean() right before it and it still did nothing...

I even tried putting header("Location: /offices"); at the very beginning of the file and it still gives me a 500.

+2  A: 

Try to use a fully formed URL:

header("Location: http://{$_SERVER['HTTP_HOST']}/offices/page-".ceil($cache->size() / 15));
deceze
I tried putting in `header("Location: http://www.example.com");` still 500 error.
animuson
@animuson Ok, that's weird. :)
deceze
Whoever it was that said put `exit` immediately after it, seems to have worked. I put `exit` right after the `header` call and it's redirecting just fine now...
animuson
Were you possibly outputting any other headers after this one?
deceze
No, the original `header` call that I was using was fairly near the end of the script execution. It would not have been possible for another `header` call to be sent that late in the script. All, if any, of them are sent right at the beginning of script execution.
animuson
+1  A: 

The script continues to execute after your header() call. You need put exit; immediately after it. This shouldn't cause a 500 error, though.

Edit: Evidently this worked - meaning your problem is probably in some related code further down the page?

jasonbar
Adding `exit` fixed the problem...
animuson
If uncommenting header() was the only other change and this fixed it then *weird*.
jasonbar