Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Negocjacja zawartości
nexis
post
Post #1





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

Ostrzeżenie: (0%)
-----


Chciałbym poznać Wasze zdanie dt. negocjacji zawartości i co za tym idzie stosowania różnych standardów. Dla przybliżenia tematu stworzyłem poniższy kod:

index.html (XHTML 1.0 Strict)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  3. <head>
  4. <title>Tytuł</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <link rel="stylesheet" type="text/css" href="css/style.css" />
  7. </head>
  8. <body>
  9. <h1>Treść</h1>
  10. </body>
  11. </html>


index.xhtml (XHTML 1.1)
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type="text/css" href="css/style.css"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
  5. <head>
  6. <title>Tytuł</title>
  7. </head>
  8. <body>
  9. <h1>Treść</h1>
  10. </body>
  11. </html>


i na koniec plik odpowiedzialny za wyświetlenie odpowiedniej wersji:
  1. <?php
  2. // Default parse HTML
  3. $xhtml = false;
  4. // XHTML compatible user agents not sending the "Accept" header
  5. $useragents = array
  6.   (
  7.      'w3c_validator',
  8.      'webkit',
  9.      'wdg_sitevalidator',
  10.      'w3c-checklink',
  11.      'web-sniffer',
  12.      'feedvalidator'
  13.   );
  14. // In case of empty headers
  15. $_SERVER['HTTP_ACCEPT'] = (isset($_SERVER['HTTP_ACCEPT'])) ? $_SERVER['HTTP_ACCEPT'] : '';
  16. $_SERVER['HTTP_USER_AGENT'] = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : '';
  17. // Checking the user agent
  18. foreach ($useragents as $useragent) {
  19.   if (false !== stripos($_SERVER['HTTP_USER_AGENT'], $useragent)) {
  20.      $xhtml = true;
  21.      break;
  22.   }
  23. }
  24. // Checking the "Accept" header
  25. if (false === $xhtml) {
  26.   if (false !== stripos($_SERVER['HTTP_ACCEPT'] , 'application/xhtml+xml')) {
  27.      $xhtml = true;
  28.   }
  29. }
  30. // Output
  31. header('Content-Type: ' . ((true === $xhtml) ? 'application/xhtml+xml' : 'text/html') . '; charset="utf-8"');
  32. readfile('index.' . ((true === $xhtml) ? 'x' : '') . 'html');
  33. ?>


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?
Go to the top of the page
+Quote Post

Posty w temacie
- nexis   Negocjacja zawartości   11.11.2008, 01:06:55
- - Zyx   Takie coś to nie jest do końca negocjacja zawartoś...   11.11.2008, 08:47:39


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.09.2025 - 19:31