【问题标题】:Remove Content-Type header in apache删除 apache 中的 Content-Type 标头
【发布时间】:2013-08-22 00:26:15
【问题描述】:

如何在 apache 中删除 header 内容类型?

以下代码不起作用

header_remove('content-type');

【问题讨论】:

    标签: php apache http-headers content-type


    【解决方案1】:

    这取决于你有什么 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');
    

    【讨论】:

      【解决方案2】:

      试试

      <?php
      header('Content-Type:');
      

      这从响应中完全删除了 Content-Type 标头。像你一样,使用header_remove() 并没有做任何事情,Hereblur's answer 在回复中给我留下了Content-Type: none

      【讨论】:

      • 不起作用,标题仍然顽固地发送。你的设置是什么?
      • PHP 5.5.14、Apache 2.4.9、Drupal 7.34 — 你的设置是什么?如果您使用某种框架,它可能会尝试巧妙地设置标题。
      • 我不在框架上。我有一个全新的 PHP 安装(Win 8.1)并且正在运行 built-in web server(没有 Apache)。
      • 不幸的是,我所知道的都写在我的回答中。我建议发布一个针对 PHP 及其内置 Web 服务器的新问题。
      【解决方案3】:

      试试这个。

      header("content-type: none");
      

      我不知道为什么,但它对我有用。

      我找不到任何提到的参考资料。但它只是为我从标题中删除了content-type。它可能是 apache 的错误或 PHP 的错误。所以请尝试并谨慎使用。

      【讨论】:

        猜你喜欢
        • 2017-10-08
        • 2016-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多