1

I saw this header(X-PHP-Response-Code) here in this SO answer and was wondering.

  1. What is the function and are there any other X-PHP-* headers?
  2. If there are what is their function and usage (as much info as possible)?
  3. If this is the only one (in which I doubt) ignore 2.

2 Answers 2

2

In the example given, the header does exactly nothing, which is exactly the point.

HTTP headers starting with X- are precisely not standardized, so anyone can set such a header knowing that it doesn't mean anything specific. The point in the case you cite is simply to use the header function to set the response code. To do that, some header needs to be supplied. The user chose to use the otherwise meaningless header X-PHP-Response-Code, simply to be able to give some header to header() in order to use its third argument to set the response code.

In other words: it's a hack.

Sign up to request clarification or add additional context in comments.

Comments

2

Headers starting with X- are not standard and their interpretation is entirely dependent on a client that looks for them and knows what they are supposed to mean.

This particular header does not have any meaning, it's just placeholder text to satisfy an extra requirement of the header function when a third argument http_response_code is supplied:

http_response_code

Forces the HTTP response code to the specified value. Note that this parameter only has an effect if the string is not empty.

6 Comments

It's so unuseful that the manual does not state whether the specified header string gets sent when you pass the http_response_code int.
@CodeCaster: Well, header's main job is to send header strings and the response code argument is optional. It may not say so explicitly, but it's not hard to connect the dots. :-)
It's not that easy. The header(string, bool, http_response_code) overload sends the special status-line of an HTTP response: HTTP/1.1 $http_response_code $textual_representation. If you don't specify the response code in the header() call, a new header gets sent with the string contents. I'm just wondering what happens to the string when you do specify the response code, given nothing happens if you don't. I guess it gets ignored, but the manual is silent on that point.
@CodeCaster: It doesn't get ignored. The call to header does not actually send the status line; it just notes down what status code will be emitted when the status line is actually sent. It does the same with the custom header. You could say that if you pass the status argument then a header call is responsible for two lines of headers, but I don't like that description because the status line will be sent anyway, even with no header calls.
@CodeCaster: Yes, although on my machine the header is not actually sent if it does not have a colon. So header('foo', true, 500) sets the status code without sending a bogus header. In any case, if the custom header bothers you (and I see no reason why it should) then you can simply use the other option: header('HTTP/1.1 500').
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.