Sending server status codes...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MacGoose
Forum Newbie
Posts: 4
Joined: Wed Jan 27, 2010 11:38 am

Sending server status codes...

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sending server status codes...

Post 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.
MacGoose
Forum Newbie
Posts: 4
Joined: Wed Jan 27, 2010 11:38 am

Re: Sending server status codes...

Post 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
Post Reply