tags: apache   archive   business   charity   climbing   comic   communication   database   email   exchange   family   fm2008   hack   hardware   humour   linux   liverpool   microsoft   money   mysql   network   oes   opensource   outlook   php   pictures   process   project   quote   real_life   review   rss   science   security   software   thought   tsm   updates   webdev   website   windows  

XHTML Delivery

Tue, 31 Jul 2007 07:26:59

I was working on the gravity magazine website last night. After making a couple of changes I ran a validation check to ensure everything still conformed to XHTML 1.1 standards. Everything passed, but I was warned that although the page conformed to standards it was being severed as a html/text document. I looked into this and found the page should be getting sent as 'Content-type: application/xhtml+xml' to truly meet XHTML 1.1 standards. An immediate problem with this is IE does not currently support this standard and was unable to load the page. I came across the following PHP script which asks the browser what formats it supports and then delivers the page in either application/xhtml+xml or html/text. I found another script which checks if the validator is testing your page, and if so delivers it as application/xhtml+xml. I merged the two and all is well.

PHP

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

Make sure this is put before any white space on your page or you'll receive an "http header type already sent" error message.

Enjoy
Ryan Partington

keywords: xhtml 1.1, application xml, html, text, content-type