Difference in sending HTTP status codes from php
what is the difference from setting the responce status in php
header("HTTP/1.0 404 Not Found"开发者_StackOverflow);
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.
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)
精彩评论