Page 1 of 1

Sending server status codes...

Posted: Wed Jan 27, 2010 12:04 pm
by MacGoose
Is it possible to send for example the 500 Internal Server Error status code to the client through PHP?

I have a few databases with some error handling when dealing with them:

Code: Select all

mysql_select_db( "database" ) or die( "Unable to select database!" );
This is somewhat the standard way of dealing with an error selecting a database. But I simply just want the server to send a 500 code the the client. If that database can't be selected there is no need for any of the page to be shown and there is no need for the user to know what went wrong just that something did. But I don't like the simple single line of text that the code above shows if an error occur. I find it much more accurate and well-known to show the 500 status page.

, MacGoose

Re: Sending server status codes...

Posted: Wed Jan 27, 2010 12:08 pm
by requinix

Code: Select all

header("HTTP/1.1 500 Internal Server Error");
// other headers
// other output?
exit;
Mind you, that won't display a fancy error page. If you're thinking of the page Apache shows, that's exactly it: Apache shows that page, not the browser - except IE, which likes showing its own error pages.

Re: Sending server status codes...

Posted: Wed Jan 27, 2010 12:32 pm
by MacGoose
Thanx!

Exactly what I need. Though it seems it can't be done as easily as I thought. All I get is a PHP error saying that the header has already been sent. I don't want to recreate everything just so I can send the header when I need to so error handling will just be as it is for now...

, MacGoose