views:

40

answers:

1

what is the difference from setting the responce status in php

header("HTTP/1.0 404 Not Found");

and

header("Status: 404 Not Found");

What is the difference from the client point of view (aka browser or a client implementation for RESTful WS). I understood that the second one has to do something with CGI.

+4  A: 

HTTP/1.0 404 Not Found is the HTTP response code, it's what allows clients to determine whether a request succeeded or not.

Status: 404 Not Found just sets an extra header field called Status with the value of 404 Not Found. It has no intrinsic meaning, it's like setting header('Foo: Bar'). It may mean something to somebody, but it's not officially specified what it should mean. The HTTP response code will be a normal 200 OK.

There seems to be a special case when running PHP through FastCGI. Apparently you can't set the HTTP/ status directly when invoking PHP with this method. Instead you have to set this unofficial header, which will be converted to a real HTTP/ code before it's send back to the client (apparently a limitation of how PHP can talk to the web server when invoked via CGI). In all other cases, it'll just be send as-is (with no meaning) and the real HTTP response code will be 200 OK.
That's what I could gather from the description in the manual at least, I've never had to use this. Also, you're insane if you run PHP through CGI, so hopefully nobody needs this in this day and age. ;o)

deceze
thanks. i find it quite strange that the HTTP response code is sent like this from php. Do you know if for example i write "HTTP/1.0 404 Found no doggy" is it going to be recognized as the 404 response or is it analyzing the whole string?
@user PHP only pays attention to the beginning of the string. If it starts with `HTTP/`, it takes the whole thing as the HTTP response code. And yes, you *can* send `HTTP/1.0 404 Found no doggy`. Most clients will probably even accept this, since they probably only look at the number, not the text.
deceze