Page 1 of 1

Internet Explorer and Content-Type: text/plain

Posted: Thu Oct 15, 2009 2:11 pm
by McInfo
Is there a way to force Internet Explorer (7) to display dynamically-generated pages that include a "Content-Type: text/plain" header the same way it displays static text files (files ending in ".txt")? In other words, force IE to display the content in the browser (the way Firefox does) instead of treating the content like a file.

text.php

Code: Select all

<?php
header('Content-Type: text/plain');
echo 'This should be displayed in the browser window, '
   . 'not opened by a separate application or saved as a file.';
?>
I tried adding a "Content-Disposition: inline" header to the script. That had no effect.

If it can be achieved by adding or changing headers, that would be acceptable, but I'm actually asking for a way to configure IE. I've looked through Internet Options without finding anything. I've also tried a few searches online without finding any exact matches to my question.

Edit: This post was recovered from search engine cache.

Re: Internet Explorer and Content-Type: text/plain

Posted: Thu Oct 15, 2009 2:51 pm
by Eric!
I think that IE like most MS products tries to help you too much. If it finds things that looks like HTML it renders them as HTML and ignores the content-type.

Do the pages you're generating have HTML in them? Or is your simple example without HTML also not working like you would expect?

FYI--I came across info about other people who had this problem some time ago when I was battling some other IE header problem...here's a link http://www.howtocreate.co.uk/wrongWithI ... xt%2Fplain

Also, I found some of the people at http://www.htmlforums.com/ to be pretty good with IE weirdness....so you could try them too.

Re: Internet Explorer and Content-Type: text/plain

Posted: Fri Oct 16, 2009 4:01 pm
by McInfo
Thanks for answering.

The files that exhibit this behavior are just like the example I posted. There is no HTML.

Just for thoroughness, I tried adding the "IsTextPlainHonored" key to the registry as is recommended to fix the text-as-HTML problem to see if that would fix my problem, but it had no effect.

One thing that does work (though it's not ideal) is changing the file extension from ".php" to ".txt" and telling Apache to send files with ".txt" extensions through the PHP parser.

.htaccess

Code: Select all

AddType application/x-httpd-php .txt
Like you say, this appears to be another case of Microsoft developers being too "helpful" but not being helpful enough to provide a way to be less "helpful".

Edit: This post was recovered from search engine cache.

Re: Internet Explorer and Content-Type: text/plain

Posted: Fri Oct 16, 2009 4:57 pm
by Eric!
I just remembered something I worked on with mime-types and IE screwing it all up.

Try playing with options for these IE header types. Perhaps the noopen to open...?

Code: Select all

header("X-Download-Options: noopen"); // IE7 & IE8?
header("X-Content-Type-Options: nosniff"); // IE8 bonus?
When I looked into the sniffing thing again today I saw this article
https://connect.microsoft.com/IE/feedba ... kID=354921
Micro$oft wrote:At this time we do not plan on fixing this issue, part of the reasoning is that changing this behavior can impact existing applications. We appreciate the report, but unfortunately we are at a stage where need to choose what we work on to maximize the value for customers and web developers. For a workaround, please use 'X-Content-Type-Options: nosniff' header (http://blogs.msdn.com/ie/archive/2008/0 ... pdate.aspx)"

Re: Internet Explorer and Content-Type: text/plain

Posted: Fri Oct 16, 2009 10:02 pm
by McInfo
Those headers looked promising, but no luck. I tried them individually and together with no change. IE still gives me a File Download dialog.

The X-Download-Options headers doesn't seem to apply to my problem.
AwghBlog wrote:The web server can set the response header “X-Download-Options” to the value “noopen”. This will tell Internet Explorer to only offer the option to save the file or cancel. It simply removes the “Open” option when this option is set.
Maybe I'll just go back to ignoring IE. I'm convinced that the only reason someone would choose to use IE on their personal computer is that they don't know that other browsers exist.

Edit: This post was recovered from search engine cache.

Re: Internet Explorer and Content-Type: text/plain

Posted: Fri Oct 16, 2009 10:44 pm
by Eric!
Bummer. Unfortunately there are a lot of people that don't know about other browsers. I've spent a lot of time trying to make things work in IE because of it. Sometimes I have to just go with the lowest common denominator and scale things back for IE.... :?

Do you have the same problem with IE8?

Re: Internet Explorer and Content-Type: text/plain

Posted: Sat Oct 17, 2009 12:09 am
by McInfo
I haven't bothered to update IE for a while because I use it so infrequently. I just have version 7.

Edit: This post was recovered from search engine cache.

Re: Internet Explorer and Content-Type: text/plain

Posted: Sun Oct 18, 2009 3:56 pm
by McInfo
I have found a work-around of sorts. It's not exactly what I want, and not exactly a reliable fix for all users, but it fools IE into thinking it is requesting a text file so it displays the content as intended.

Just append a string like "/non-existent-text-file.txt" to the end of the URL. All that matters is that the string begins with "/" and ends with ".txt" so IE thinks it's a static text file. The string could even be just "/.txt". Apache will see that "real-file.php/non-existent-text-file.txt" does not match any file and will try to find "real-file.php". (I'm not sure if that's exactly how it works.) Because "real-file.php" exists, Apache serves it. IE doesn't know the difference.

Example:
http://localhost/book/page.php/.txt
One problem is that IE will cache the file. To prevent that, add a Cache-Control header.

Code: Select all

header('Cache-Control: no-cache');
Query strings will be forwarded to the PHP file.
http://localhost/book/page.php/.txt?id=123
Edit: Fixed spelling error

Edit: This post was recovered from search engine cache.

Re: Internet Explorer and Content-Type: text/plain

Posted: Sun Oct 18, 2009 4:16 pm
by califdon
That's really bizarre. Glad you found a workaround, but I really hate using methods that "trick" the software into doing something else. Some day a programmer will do something that will kill it. I'm sure you feel the same way.

Re: Internet Explorer and Content-Type: text/plain

Posted: Sun Oct 18, 2009 6:15 pm
by Eric!
That's a good hack. :)