你如何从PHP返回CGI标题?

你如何从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.

php如何返回CGI标题? p>

我一直在编写CGI C ++中的'scripts',这很简单:我只需手动输出 Content-type code>和 Status code>行。 但是,我需要使用phpmailer,所以我也有一些PHP代码。 问题是我的简单PHP代码正常工作,即使我没有显式返回任何标题。 我已经到了我现在必须将失败状态代码返回给客户端的地步,我无法看到我是如何做到这一点的。 有任何想法吗? Apache是​​否为我自动执行此操作,如果是,我如何说服它返回400状态? p>

谢谢。 p> div>

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