W3C home > Mailing lists > Public > www-validator@w3.org > July 2007

Re: Validator doesn't send HTTP_ACCEPT headers, "Conflict between Mime Type and Document Type" warning is incorrect.

From: Sierk Bornemann <sierkb@gmx.de>
Date: Tue, 31 Jul 2007 21:04:16 +0200
Message-Id: <B177C070-822D-4BDD-9DAE-5CEC6CFD070A@gmx.de>
Cc: www-validator@w3.org
To: Andries Louw Wolthuizen <info@andrieslouw.nl>


Am 31.07.2007 um 20:35 schrieb Andries Louw Wolthuizen:

> Because I don't want to send application/xhtml+xml to (older)  
> browsers that don't send a HTTP accept header, I've set the default  
> mime-type on text/html.
>
> My PHP script is now:
> <?php
> $charset = 'utf-8';
> $mime = 'text/html';
> if(!empty($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER 
> ['HTTP_ACCEPT'],'application/xhtml+xml')){
>     if(preg_match('/application\/xhtml\+xml;q=([01]|0\.\d{1,3}|1\. 
> 0)/i',$_SERVER['HTTP_ACCEPT'],$matches)){
>         $xhtml_q = $matches[1];
>         if(preg_match('/text\/html;q=q=([01]|0\.\d{1,3}|1\.0)/i', 
> $_SERVER['HTTP_ACCEPT'],$matches)){
>             $html_q = $matches[1];
>             if((float)$xhtml_q >= (float)$html_q) {
>                 $mime = 'application/xhtml+xml';
>             }
>         }
>     }else{
>         $mime = 'application/xhtml+xml';
>     }
> }
> if(stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") OR stristr 
> ($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") OR stristr 
> ($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")){
>     $mime = "application/xhtml+xml";
> }
> if($mime == 'application/xhtml+xml') {
>     $prolog_type = '<?xml version="1.0" encoding="'.$charset.'" ? 
> >'.PHP_EOL;
> }else{
>     $prolog_type = '';
> }
> header('Content-Type: '.$mime.';charset='.$charset);
> header('Vary: Accept');
> echo $prolog_type;
> ?>

And now the whole thing *WITHOUT* using a scripting language like PHP  
and only based on the methods and rules, a webserver like Apache  
provides. Not every website runs PHP...


-- 
Sierk Bornemann
email:            sierkb@gmx.de
WWW:              http://sierkbornemann.de/
Received on Tuesday, 31 July 2007 19:04:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:25 GMT