Problems with XHTML content type.
May 30, 2007 2:04 PM
Subscribe
I seem to have hit a bit of a brick wall in approximating W3C XHTML standards compliance on my website. From what I've read, XHTML
should be served with content type
application/xhtml+xml, rather than
text/html, and recent versions of Microsoft and Mozilla browsers should support serving them as such. Well, they aren't.
I set the content type and character set for all of my pages using the
header statement in my primary include file, as shown
here.
When I try to switch the content type (currently by commenting one line and uncommenting the other), however, the following happens:
Firefox 2.0.0.3 complains that
this XML file does not appear to have any style information associated with it, and displays a bare document trees.
Internet Explorer 7.0.5450.4 opens an Open/Save/Cancel for a file of type php_auto_file.
Opera for Wii shows the bare interface, stripped of all styling.
Can anybody help me figure out what's going wrong?
posted by The Confessor to computers & internet (13 comments total)
2 users marked this as a favorite
As for serving up XHTML, you need to check the browser's HTTP_ACCEPT header to decide whether or not to serve it (IE, including IE 7, can't handle it at all and will offer to download it).
< ?phpbr> if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {Be warned: there are a TON of gotchas involved in serving using the application/xhtml+xml content type, especially relating to JavaScript. This article from 2003 is still very relevant.header("Content-type: application/xhtml+xml");
}
else {
header("Content-type: text/html");
}
?>>
posted by simonw at 2:13 PM on May 30, 2007