Someone in my studio designed a webpage some years ago, and now the client decided to change the server (he moved to a Linux Apache server running Gen2 SMP, 64 bits, PHP version 5.3.8, Standard MYSQL version 5). It suddenly started to do weird things.
When clicking on a link that requires login, the page redirects you to the login page using header()
function in PHP. Curiously, the page shows this:
OK
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. HTTP/1.1 200 OK Date: Mon, 15 Oct 2012 17:27:32 GMT Server: Apache/2.2.22 (Unix) FrontPage/5.0.2.2635 X-Powered-By: PHP/5.3.8 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Keep-Alive: timeout=5, max=399 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html 232c
Then the page itself, and then, another header:
0 1f4
OK
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. 0
What's most intriguing is that if you refresh the page or hit enter on the url, it loads correctly. I've been checking the logs, and it only blames of an inexisting favicon. I also checked the .htaccess, everything was correct (RewriteBase was / as intended, and the only stuff there is another rule that moves ^en/ requests to request?lang=en. Has anyone faced something like this?
Edit: IE doesn't trigger these two headers. This is getting wierder.
The solution!: As @adaptr pointed out, it was a matter of PHP and not any server related thing. The last coder (I know it's not polite to blame the predecessor, but this situation has taken me too much time) did this:
/* config.php -> included everywhere as a bootstrap*/
// ... constant/mysql setup
if($notLogged)
{
$forward = ...;//previous url
header("Location: ".WWW.LANG."/customer-area/login/index.php?forward=".$forward);
exit;
}
After looking deeper, something twisted me: exit;
would correctly send the headers, or wouldn't? Of course, removing that exit;
would keep executing the page (I know it's not correct at all, that's why I didn't try it before). However, if the headers weren't being completely sent, it could cause any kind of problem (I'm not a server guy, I'm not sure about that, sorry mates). After removing that exit;
call, the page was being correctly formed, the headers got "closed" (because of the output start) and all the gears started moving again. Thank you all, guys, best bountied 100 points =)