Send the HTTP request Accept header

i was getting a warning when trying to validate any page on my site that 
the mime type is text/html instead of application/xhtml+xml when the 
document type is xhtml 1.1.  at the time i was using code very similar 
to what was suggested under the “setting the mime type with php” heading 
of the document [1] the validator’s warning message linked to:

if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml"))
    header("Content-Type: application/xhtml+xml; charset=utf-8");
else
    header("Content-Type: text/html; charset=utf-8");

if you’re curious, i’m using stripos() !== false instead of stristr(), 
but other than that (and that i use single quotes and don’t put a space 
after if) i came up with identical code on my own.

the problem is that when the w3c html validator looked at my site, the 
Accept header was blank or missing, so my server sent text/html.  i’ve 
now updated my logic to say if accept contains application/xhtml+xml or 
doesn’t contain text/html, send application/xhtml+xml; otherwise fall 
back to text/html.

i think that since the validator can in fact accept 
application/xhtml+xml, it should say so in the Accept header.  i’d like 
to see application/xhtml+xml, text/html and all other mime types the 
validator is capable of validating sent in the Accept header when 
requesting a file to validate.

thanks!

[1] http://juicystudio.com/article/content-negotiation.php

Received on Saturday, 2 August 2008 09:18:01 UTC