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

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 UTC