Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6653475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:16:26+00:00 2026-05-26T01:16:26+00:00

Short question: Can I rely on the behaviour of header(‘.’, TRUE, 404); , header(‘.’,

  • 0

Short question: Can I rely on the behaviour of header('.', TRUE, 404);, header('.', TRUE, 501);, etc.?

Now, let me elaborate.

Before asking my question, I’ll present a few usages of the header() call and the corresponding HTTP response code generated by it.

header('HTTP/1.1 404 Bummer!'); — HTTP/1.1 404 Bummer!

header('HTTP/1.1 501 I am sick'); — HTTP/1.1 501 I am sick

header('Bummer!', TRUE, 404); — HTTP/1.1 404 Not Found

header('I am sick', TRUE, 501); — HTTP/1.1 501 Method Not Implemented

So, we can see that if we use the third parameter while the first parameter is junk, the first parameter is ignored. However, the documentation at http://php.net/manual/en/function.header.php says:

Note that this parameter only has an effect if the string is not
empty.

So, we still have to put something in the first parameter. This looks a bit ugly to me because the $string is ignored when we specify $http_response_code in the third parameter but we are still required to put some value for $string even though it will never be used.

But I can understand why this turned out this way. Traditionally, header() accepted only parameter and we could set arbitrary response codes like in the first two examples. The second and third parameters were added later as optional paramters. So, we have to specify something for the first parameter if we want to use the second and third. Moreover, sometimes we may need to put valid headers in the first parameter along with a valid response code in the third parameter. I have included one such example in the end.

So, I’m planning to use this function in this manner in my code: header('.', TRUE, 404);, header('.', TRUE, 501);, etc. As per the examples above, it’ll produce correct HTTP responses as per the standard. I want to know if I can rely on this behaviour. I ask this question because I can’t find the documentation mentioning explicitly that the first parameter ($string) is going to be ignored when we provide the third ($http_response_code).

BTW, I know that the first argument can be useful in situations like this.

header('Foo: Bar', TRUE, 501); leads to:

HTTP/1.1 501 Method Not Implemented
Date: Sun, 09 Oct 2011 19:01:19 GMT
Server: Apache/2.2.20 (Debian)
X-Powered-By: PHP/5.3.8-1
Foo: Bar
Vary: Accept-Encoding
Connection: close
Content-Type: text/html

A more practical example is header('Location: http://example.com/there/', TRUE, 307); which would generate:

HTTP/1.1 307 Temporary Redirect
Date: Sun, 09 Oct 2011 19:09:29 GMT
Server: Apache/2.2.20 (Debian)
X-Powered-By: PHP/5.3.8-1
Location: http://example.com/there/
Vary: Accept-Encoding
Content-Type: text/html

Anyway, back to my question. Can I rely on the behaviour of header('.', TRUE, 404);, header('.', TRUE, 501);, etc.?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:16:27+00:00Added an answer on May 26, 2026 at 1:16 am

    Not sure if you’re looking for this, but I guess you don’t want to build the HTTP status line:

    header('.', TRUE, 501);
    

    Makes my Apache return this status line:

    HTTP/1.1 500 Internal Server Error
    

    But

    header(' ', TRUE, 501);
    

    Makes my Apache return this status line:

    HTTP/1.1 501 Not Implemented
    

    Which might be what you’re looking for.

    Maybe you just want to build the status line?

    header('HTTP/1.1 501 No Implementation for you :)');
    

    Which makes my Apache return this status line:

    HTTP/1.1 501 No Implementation for you :)
    

    Traditionally, it’s done this way:

    header('HTTP/1.1 501');
    

    Which get’s some default status line message text then:

    HTTP/1.1 501 Method Not Implemented
    

    This does not change the protocol version:

    header('HTTP/1.0 404');
    

    As it gives:

    HTTP/1.1 404 Not Found
    

    Hope this helps.


    Update by Susam:

    With PHP 5.4, a simple and elegant way to do this is:

    http_response_code(404);
    

    or

    http_response_code(501);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short question: Can anyone tell me what the requirements (especially when it comes to
A short question: I've got a TabNavigator with multiple canvas children. How can i
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
The short version of the question - why can't I do this? I'm restricted
This question will be short and sweet. I know an instruction can occur between
I have a very short question: How can i fetch mysql content using php
Short question is: how can i use graph api oauth redirects mechanism to authenticate
The short question is - how can I prevent (delay) a bound UI element
Short question: How can I modify individual items in a List ? (or more
Just a very short question: How can I find out if the MPMoviePlayerController instance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.