I'm trying to implement a very simple shorthand function for sending headers, based on this answer.
The function goes like this:
function hdr($code)
{
if (!headers_sent())
{
header('x', TRUE, $code);
}
}
Now, it works well in my local server, but once I go into production I get a 500, and the following form the error log:
[Tue Jun 19 11:01:59 2012] [error] [client 87.12.83.179] malformed header from script. Bad header=x: php54.cgi
If i modify the function as such:
function hdr($code)
{
if (!headers_sent())
{
header($_SERVER['SERVER_PROTOCOL'], TRUE, $code);
}
}
It works on production, but not locally.
I guess the problem is with the production php being a cgi script? Any way to solve the problem (ie. have one function for all) without going with an associative array of 'codes' => 'messages'?