title: iPhone4 retina display detection with PHP and/or JavaScript
body: <p>I'm creating a detection script that sniffs out any device (currently only iPhone4) with a retina display (or similar) when a user arrives at my site. Because the resolution is greater, I need to push higher res images/graphics. The only solution that I can find (using PHP and JavaScript) is to detect the <code>devicePixelRatio</code> and set a cookie. Here is the code that I am using:</p>
  
  
  
  <pre><code>&lt;?php
      $imgPath = "images/";
      if(isset($_COOKIE["imgRes"])){
          $imgRes = $_COOKIE["imgRes"];
          if( $imgRes  &gt;= 2 ){
              $imgPath = "images/highRes/";
          }
      } else {
  ?&gt;
      &lt;script language="javascript"&gt;
          var the_cookie = "imgRes="+window.devicePixelRatio+";"+the_cookie;
          document.cookie = the_cookie;
          location = '&lt;?=$_SERVER['PHP_SELF']?&gt;';
      &lt;/script&gt;
  &lt;?php
      }
  ?&gt;
  </code></pre>
  
  <p>Has anyone come across a better method of doing this or have any suggestions of improving this script. This script does work, it just feels dirty.</p>