0

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.

3 Answers 3

2

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

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

Php has this function for things like you need:

Php header

Example:

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

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

PHP Header

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.