Recent changes RSS feed
 

HTTP Header Manipulation

Content Types

XHTML content should be served by the MIME type: application/xhtml+xml but many browsers will only recognize the standard MIME type: text/html

Web standards recommend that 1.0 versions of XHTML can be served by the text/html type, but 1.1 versions can not.

Currently, very few sites can assume that the application/xml type will be universally accepted. The simple solution is to implement doctype switching, based on the browsers HTTP_ACCEPT properties:

<?php
 
if (stristr($_SERVER~["HTTP_ACCEPT"],"application/xhtml+xml")) {
 
    header("Content-Type: application/xhtml+xml; charset=UTF-8");
    echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
            "~http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');
 
} else {
 
    header("Content-Type: text/html; charset=UTF-8");
    echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
             "~http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
 
}
 
?>

Mozilla treats the application/xml content type as an XML application, and will fail if the markup is not well formed.

 
php/http_header_manipulation.txt · Last modified: 2006/12/09 17:15
 
Hosting for this site donated by Procata PHP Development