Remove Content-Type header in apache
Asked Answered
Y

4

8

How to remove header content-type in apache ?

The following code does not work

header_remove('content-type');

Yvoneyvonne answered 20/8, 2013 at 4:6 Comment(0)
G
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.

Granulite answered 20/8, 2013 at 4:14 Comment(0)
K
6

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.

Kesselring answered 24/7, 2014 at 18:46 Comment(4)
Doesn't work, header still stubbornly gets sent. What's your setup?Bowling
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.Kesselring
I'm not on a framework. I've got a fresh PHP installation (Win 8.1) and am running the built-in web server (no Apache).Bowling
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.Kesselring
L
6

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');
Lyric answered 18/2, 2015 at 17:12 Comment(0)
G
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.

Granulite answered 20/8, 2013 at 4:14 Comment(0)
W
0

If you are using the bellow line and do not have access to php.ini:

#!/usr/local/bin/php

You can add -q at the end of it and the headers will be removed, because header_remove will not remove Content-type.

#!/usr/local/bin/php -q
Widener answered 3/6 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.