title: Whats better to redirect, screen resolution or user agent?
body: <p>I've created a mobile web page for a site but I'm wondering what the best method for redirection is.  Do I redirect them based on the screen resolution or the user agent?  </p>
  
  <p>I would assume screen resolution would look something like this:</p>
  
  <pre><code>if (screen.width &lt;= 1024) window.location.replace("http://www.site/mobile/")
  else window.location.replace("http://www.site/");
  </code></pre>
  
  <p>Using PHP the script would look something like this:</p>
  
  <pre><code>$useragent=$_SERVER['HTTP_USER_AGENT'];
  if(preg_match('/android/i',substr($useragent,0,4)))
  header('Location: http://www,site/mobile/');
  </code></pre>
  
  <p>Is one method preferred over the other? If so what are the advantages?</p>