Anne van Kesteren

MIME-Types

This is my first post about XHTML, at least I think it is. First of all, how do you change Nuclues to send the correct headers. It’s a little complicated but eventually it worked. Nucleus works with a different skin for every page. For the parts that remain the same, like the top and the bottom of my XHTML (valid) code, I use Nuclues includes. I changed my top.php.inc a little bit. Just before the XML-prolog I added this:

<%phpinclude(mimeheader.inc.php)%><?xml version="1.0" encoding="ISO-8859-1"?>

Note that they follow each other with no space(!) this is important. The file that is includes contains PHP:

<?php
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
  header("Content-type: application/xhtml+xml");
}
else{
  header("Content-type: text/html");
}
?>

If the UA accepts application/xhtml+xml then it will get it (Go Mozilla!) else it will get text/html (You guessed IE? Correct!). It’s really nice to send it as XML. If there is an error in you validation the layout will just crash! And I love that, because I don't have the time to check with the validator each time, now I can just check my page with my default browser and check it breaks or not.

And then you have to change the class ADMIN.php as well. More information can be found here.

Folkert validates now as XHTML 1.0 Strict and he even sends stuff as application/xhtml+xml; brilliant!

Here are some links on the MIME fuzz:

Comments

  1. What if someone specifies application/xhtml+xml;q=0? :-)

    Posted by Jan! at

  2. What do mean?

    I'll try to give an answer: "If you send it as application/xhtml+xml you'll send your code as it was XML. It your code is not well-formed the browser returns an error. Also some XML rules come in.

    Posted by Anne at

  3. Setting q=0 in HTTP_ACCEPT would mean that you DON'T want to receive application/xhtml+xml (if I remember correctly).

    Here's how to handle things using the next Nucleus version (or current CVS snapshot):

    (yeah, application/xhtml+xml;q=0 would fool this too :))

    Posted by karma at