你如何从PHP返回CGI标题?

How does php return CGI headers?

I've been writing CGI 'scripts' in C++, and this is straightforward: I just manually output a Content-type and a Status line. However, I need to use phpmailer, so I also have some php code. The problem is that my simple php code just works, even though I'm not explicitly returning any headers. I've got to the point where I now have to return a failure status code to the client, and I can't see how I'm meant to do this. Any ideas? Is Apache doing this automatically for me and, if so, how do I persuade it to return a 400 status?

Thanks.

As per the docs, send a header that starts with "HTTP/".

header("HTTP/1.0 400 Bad Request");

Php has this function for things like you need:

Php header

Example:

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

You may use the header function to add custom headers. Please refer to the header function documentation.

PHP Header