I’m trying to set the response code in a PHP script to 200. Later I set a Location header, which sets it to 302. According to the documentation:
Not only does it send this header back to the browser, but it also
returns a REDIRECT (302) status code to the browser unless the 201 or
a 3xx status code has already been set.
Is there no way to set the header to 200 and not have the location header override it? I’ve tried setting the response code header after the location header, but that doesn’t work (presumably because the location header has already been sent along with the body including the “Found” HTML bit).
I could use 201 as the response code, since the application accecssing the script only checks for any 2xx code. However, according to the HTTP 1.1 spec:
The origin server MUST create the resource before returning the 201 status code.
But I’m not creating anything. Is that a problem, or can I get away with it?
Well, I found an answer to my particular problem. My original problem was that one place needed the
redirectheader and another place needed theHTTP/1.1 200 OKheader, so I was able to use one or the other depending on the source.However, after trying the 201 option, that didn’t work either, (still 302) so I don’t know if that’s a bug or if I was doing it wrong or what.