【发布时间】:2013-08-22 00:26:15
【问题描述】:
如何在 apache 中删除 header 内容类型?
以下代码不起作用
header_remove('content-type');
【问题讨论】:
标签: php apache http-headers content-type
如何在 apache 中删除 header 内容类型?
以下代码不起作用
header_remove('content-type');
【问题讨论】:
标签: php apache http-headers content-type
这取决于你有什么 php.ini 指令,以及你使用什么 PHP(CLI、CGI、...)。
此答案基于 PHP 5.4,在 CGI 中运行。
php.ini 中的注释:
default_mimetype = text/html
这是 PHP 发送的默认值:
Content-Type: text/html
如果你想去掉它,你必须通过重新创建表头来删除默认值,然后你可以删除表头:
<?php
header('Content-Type: text/html');
header_remove('Content-Type');
【讨论】:
试试
<?php
header('Content-Type:');
这从响应中完全删除了 Content-Type 标头。像你一样,使用header_remove() 并没有做任何事情,Hereblur's answer 在回复中给我留下了Content-Type: none。
【讨论】:
试试这个。
header("content-type: none");
我不知道为什么,但它对我有用。
我找不到任何提到的参考资料。但它只是为我从标题中删除了content-type。它可能是 apache 的错误或 PHP 的错误。所以请尝试并谨慎使用。
【讨论】: