7

How to remove header content-type in apache ?

The following code does not work

header_remove('content-type');

donut
  • 9,427
  • 5
  • 36
  • 53

3 Answers3

5

Try

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

This completely removed the Content-Type header from the response. Like you, using header_remove() didn't do a thing and Hereblur's answer left me with Content-Type: none in the response.

Community
  • 1
  • 1
donut
  • 9,427
  • 5
  • 36
  • 53
  • Doesn't work, header still stubbornly gets sent. What's your setup? – Pacerier Feb 05 '15 at 11:56
  • PHP 5.5.14, Apache 2.4.9, Drupal 7.34 — What's your setup? If you're using a framework of some sort it may be trying to be smart about setting the headers. – donut Feb 06 '15 at 16:32
  • I'm not on a framework. I've got a fresh PHP installation (Win 8.1) and am running the [built-in web server](http://php.net/manual/en/features.commandline.webserver.php) (no Apache). – Pacerier Feb 08 '15 at 15:40
  • Unfortunately, all I know about this is written in my answer. I would suggest posting a new question specific to PHP and the its built-in web server. – donut Feb 09 '15 at 16:55
5

It depends on what php.ini directives you have, and what PHP you use (CLI, CGI, ...).

This answer is based on PHP 5.4, running in CGI.

Note in php.ini:

default_mimetype = text/html

That's the default value, that PHP sends as:

Content-Type: text/html

If you want to get rid of it, you have to remove the default value by creating the header again, then you can remove the header:

<?php
header('Content-Type: text/html');
header_remove('Content-Type');
Yvan
  • 2,539
  • 26
  • 28
2

Try this.

header("content-type: none");

I don't know why, but it's worked for me.

I cannot find any reference mentioned about this. but it's simply removed the content-type from header for me. It' may be apache's bug or PHP's bug. So try it and use it with careful.

Hereblur
  • 2,084
  • 1
  • 19
  • 22