index.html (XHTML 1.0 Strict)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> <body> </body> </html>
index.xhtml (XHTML 1.1)
i na koniec plik odpowiedzialny za wyświetlenie odpowiedniej wersji:
<?php // Default parse HTML $xhtml = false; // XHTML compatible user agents not sending the "Accept" header ( 'w3c_validator', 'webkit', 'wdg_sitevalidator', 'w3c-checklink', 'web-sniffer', 'feedvalidator' ); // In case of empty headers $_SERVER['HTTP_USER_AGENT'] = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : ''; // Checking the user agent foreach ($useragents as $useragent) { if (false !== stripos($_SERVER['HTTP_USER_AGENT'], $useragent)) { $xhtml = true; break; } } // Checking the "Accept" header if (false === $xhtml) { if (false !== stripos($_SERVER['HTTP_ACCEPT'] , 'application/xhtml+xml')) { $xhtml = true; } } // Output header('Content-Type: ' . ((true === $xhtml) ? 'application/xhtml+xml' : 'text/html') . '; charset="utf-8"'); ?>
Co według Was przemawia za stosowaniem tego typu mechanizmów, a co przeciw? Czy macie jakieś uwagi lub własne pomysły do powyższego kodu?