Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.
share|improve this question

2 Answers

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.

share|improve this answer

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.

share|improve this answer
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 14 hours ago
1  
@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. :-) – Jon 14 hours ago
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 13 hours ago
@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. – Jon 13 hours ago
1  
@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'). – Jon 13 hours ago
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.