- From: Gez Lemon <gez@juicystudio.com>
- Date: Tue, 31 Jul 2007 16:49:46 +0100
- To: "Sierk Bornemann" <sierkb@gmx.de>
- Cc: "Andries Louw Wolthuizen" <info@andrieslouw.nl>, "www-validator Community" <www-validator@w3.org>
On 31/07/07, Sierk Bornemann <sierkb@gmx.de> wrote: > Of course, this would be sane. But how to translate into a working > solution *without* asking the client's (in this case the valdator's) > accept header? > Any suggestion? Any algorithm out there (for PHP or JSP or other > frameworks) does rely on the browser's accept header and asks for the > *existance* of "application/xhtml+xml" in the accept header of the > client. > I, so far, have never seen any working solution, which asks for the > *non-existance* of "application/xhtml+xml". All implementations of > the algorithm cited, I have seen so far, do ask for the *existance* > of "application/xhtml+xml". > So, how would you implement the *opposite* of that, if you have > requesting user agents, which provide an empty accept header string > or provide a meaningful "*" as the Internet Explorer does? You could first check that there is an HTTP_ACCEPT header. If not, deliver application/xhtml+xml; otherwise, test if application/xhtml+xml is in the accept header. That caters for all the scenarios you mentioned. The following serves text/html to IE, application/xhtml+xml to Firefox (and other browsers that state they can handle it), and application/xhtml+xml to the validator (as it doesn't send the accept header): header("Vary: Accept"); if ($_SERVER[HTTP_ACCEPT]) { if (stristr($_SERVER[HTTP_ACCEPT], "application/xhtml+xml") === FALSE) { header("Content-Type: text/html; charset=utf-8"); } else { header("Content-Type: application/xhtml+xml; charset=utf-8"); } } else { header("Content-Type: application/xhtml+xml; charset=utf-8"); } Cheers, Gez -- _____________________________ Supplement your vitamins http://juicystudio.com
Received on Tuesday, 31 July 2007 15:49:53 UTC