Błąd w przełączaniu strony z Komputerowej na Mobilną

Witam.

W sieci znalazłem następujący sposób na przełączanie zawartości strony:

<?php

  define('MOBILE_SITE', 'http://m.duklandosk.tk');

  define('DESKTOP_SITE', 'http://duklandosk.tk');


  if($_REQUEST['redirect']=='false') {

    header('Location: ' . DESKTOP_SITE );

    exit;

  }


  define('DA_USE_COOKIES', true);

  define('DA_USE_CACHE', true);

  define('DA_CACHE_DIR', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'DeviceAtlasCache' . DIRECTORY_SEPARATOR);

  define('DA_URI', 'http://detect.deviceatlas.com/query');

  $da_results = array('_source' => 'none');


  if (DA_USE_COOKIES && isset($_COOKIE['Mobi_Mtld_DA_Properties'])) {

      $da_results = (array)json_decode($_COOKIE['Mobi_Mtld_DA_Properties'], true);

      $da_results['_source'] = 'cookie';

  }

  if (DA_USE_CACHE && $da_results['_source'] === 'none') {

      $da_cache_file = md5($_SERVER["HTTP_USER_AGENT"]) . '.json';

      if (!file_exists(DA_CACHE_DIR) && !@mkdir(DA_CACHE_DIR)) {

          $da_results['_error'] = "Unable to create cache directory: " . DA_CACHE_DIR . "\n";

      } else {

          $da_json = @file_get_contents(DA_CACHE_DIR . $da_cache_file);

          if ($da_json !== false) {

              $da_results = (array)json_decode($da_json, true);

              $da_results['_source'] = 'cache';

              if (DA_USE_COOKIES) {

                  setcookie('Mobi_Mtld_DA_Properties', $da_json);

              }

          }

      }

  }

  if ($da_results['_source'] === 'none') {

      $da_json = @file_get_contents(DA_URI . "?User-Agent=" . urlencode($_SERVER["HTTP_USER_AGENT"]));

      if ($da_json !== false) {

          $da_results = array_merge(json_decode($da_json, true), $da_results);

          $da_results['_source'] = 'webservice';

          if (DA_USE_COOKIES) {

              setcookie('Mobi_Mtld_DA_Properties', $da_json);

          }

          if (DA_USE_CACHE) {

              if (@file_put_contents(DA_CACHE_DIR . $da_cache_file, $da_json) === false) {

                  $da_results['_error'] .= "Unable to write cache file " . DA_CACHE_DIR . $da_cache_file . "\n";

              }

          }

      } else {

          $da_results['_error'] .= "Error fetching DeviceAtlas data from webservice.\n";

      }

  }


  if($da_results['mobileDevice']) header('Location: ' . MOBILE_SITE);

  else header('Location: ' . DESKTOP_SITE);


?>

Jednak po użyciu tego, wyświetlają mi się następujące błędy:

Na stronie desktopowej

i dodatkowo

Na stronie w telefonie komórkowym (nie mobilnej)

i nie wiem co jest źle…

Pozdrawiam,

Hookz

Co do tych błędów:

Warning: Cannot modify header information - headers already

sent by (output started at /home/u647458300/public_html/

index.php:8) in /home/u647458300/public_html/index.php on

line 40

Warning: Cannot modify header information - headers already

sent by (output started at /home/u647458300/public_html/

index.php:8) in /home/u647458300/public_html/index.php on

line 64

to włącz buforowanie na serwerze lub na poczatku w kazdym pliku ktory zwroci błąd daj

<?php 

ob_start();

?>

a na końcu

<?php

ob_end_flush();

?>