How to remove headers in an array
All,
I have a PHP application that seems to generate the following headers in an array. I wish to remove these headers, so I can set new ones like the one for a pdf download.
array(2) {
[0]=>
string(23) "X-Powered-By: PHP/5.3.1"
[1]=>
string(23) "Content-type: text/html"
}
How do I do this, as this doesn't seem to wor开发者_如何学Ck:
var_dump(headers_list());
header_remove("X-Powered-By");
header_remove("Content-type");
var_dump(headers_list());
I think the lines may do the same what you exactly want to do.
header("Content-type: application/pdf");
header('Content-Disposition: attachment; filename="sample.pdf"');
readfile('/var/www/sample.pdf');
Thanks
You can only modify headers, if no output has been sent to the client yet. Thus var_dump function will cause header_remove to be ignored (since it obviously outputs text to the client).
You should also take a look out output buffering functions: http://us3.php.net/outcontrol
精彩评论