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

Posted on 2006-03-30
Last Modified: 2012-08-13
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
Question by:submissiontechnology
    1 Comment
    LVL 11

    Accepted Solution


    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$ [R,L]

    Then your offline.php script would be something like:

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


    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now