• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3446
  • Last Modified:

header("HTTP/1.1 503 Service Unavailable");

I am trying to generate a 503 error, I have put in:
header("HTTP/1.0 503 Service Unavailable");
header("HTTP/1.1 503 Service Unavailable");
header("Status: 503 Service Unavailable");

But still the page is giving 200 OK.
I'm using PHP 4.4 + Apache 2.0
0
submissiontechnology
Asked:
submissiontechnology
1 Solution
 
siliconbritCommented:

Firstly, I am not sure you can force a 503 error, since this is the Service Unavailable error.  I'm not saying 100% that it cant be done, because I do it all the time for 40X errors.

Basically, I think the "200 OK" is coming from the web server, which is reporting that it was successful in delivering the page, whatever you have put in the header statement.

You could try making sure that no whitespace is in the document, as this will force the server to write the headers before you get to output your 503.

Also try just constructing the entire HTML of a 503 page, and use that instead.  This will get around PHP automatically adding in your <html><head>...</head><body></body> section when you have not defined it.  Again, this will over-ride your 503 so you need to avoid it.

Finally, the normal way to issue a 503 (because your site is down for maintenance for example), is to use a mod_rewrite rule in an htaccess file:

   RewriteEngine on
   RewriteRule !offline.php$ http://www.mydomain.com/offline.php [R,L]

Then your offline.php script would be something like:

   <?php
   header("HTTP/1.1 503 Service Unavailable");
   echo "The site is currently offline";
   ?>
   
Hope this is a help.
   

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now