Dark Launch

Force Plain Text Format in Internet Explorer WITHOUT Registry Hack [SOLVED]

Internet Explorer uses MIME sniffing to parse pages and will erroneously render the following page as html:
PHP
header('Content-Type: text/plain');
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';

To force Internet Explorer to render the page as plain text, add the following before any text is output:
PHP
header('Content-Type: text/plain');
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo "\n";

Example:
The following will render as plain text in Internet Explorer:
PHP
header('Content-Type: text/plain');
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo '                                                 ';
echo "\n";
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';

Or simply:
PHP
header('Content-Type: text/plain');
echo str_repeat(' ', 250) . "\n";
echo '<body>';
echo '<span style="font-size:600%;">';
echo 'normal <strong>bold</strong>';
echo '</span>';


UPDATE: Sending the X-Content-Type-Options response header will stop MIME-sniffing.
PHP
header('X-Content-Type-Options: nosniff');

Comments


  1. Thanks, just what I was looking for.

  2. As used in wordpress:
    /**
    * Send a HTTP header to disable content type sniffing in browsers which support it.
    *
    * @link http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
    * @link http://src.chromium.org/viewvc/chrome?view=rev&revision=6985
    *
    * @since 3.0.0
    * @return none
    */
    function send_nosniff_header() {
    @header( 'X-Content-Type-Options: nosniff' );
    }
    http://core.svn.wordpress.org/trunk/wp-includes/functions.php