title: View full site with cookies, javascript and mobile redirect
body: <p>I have a website(www.website.com) and a mobile site (m.website.com) and I'm trying to allow users to "View Full Site" if they want from mobile.  Currently I am using some Javascript to check screen width on full site then redirecting to mobile.</p>
  
  <pre><code>if (screen.width &lt;= 699) {
  document.location = "http://m.website.com";
  }
  </code></pre>
  
  <p>This works fine.  On the mobile site there is a "View Full Site" button.  When you click this it redirects you to my script "force_desktop.php" which sets a cookie and then sends you to the main site.</p>
  
  <pre><code>&lt;?php
  setcookie("force_desktop", "1");
  header("Location: http://www.mywebsite.com");
  ?&gt;
  </code></pre>
  
  <p>Now that we set a cookie and redirected to the main website we need to check for the cookie instead of just checking for the screen width. </p>
  
  <p><strong>Logic</strong></p>
  
  <p>If Cookie force_desktop is found </p>
  
  <p>Then exit </p>
  
  <p>Else</p>
  
  <p>run screen size test</p>
  
  <p>Here is the code I attempted to use but doesn't work.  This code is placed in my head.php file which will be run on every page and is placed between the script opening and closing tags.</p>
  
  <p><strong>Attempt 1</strong></p>
  
  <pre><code>if($_COOKIE['force_desktop'] == '1' {
  exit;
  } else if($_COOKIE['force_desktop'] != '1' {
  if (screen.width &lt;= 699) {
  document.location = "http://m.website.com";
  }
  };
  </code></pre>
  
  <p><strong>Attempt 2</strong></p>
  
  <pre><code>if(isset ($_COOKIE["force_desktop"])){
  exit;
  else
  if (screen.width &lt;= 699) {
  document.location = "http://m.mywebsite.com";
  };
  </code></pre>
  
  <p><strong>Alternative logic that could work</strong></p>
  
  <p>IF Cookie force_desktop is not found AND screen.width &lt;= 699 </p>
  
  <p>Then redirect to m.myseite.com</p>
  
  <p>Else</p>
  
  <p>Exit</p>
  
  <p><strong>Note</strong></p>
  
  <p>I have run the following script to make sure a cookie is being placed, and it is.</p>
  
  <pre><code>&lt;?php
  print_r($_COOKIE);
  ?&gt;
  </code></pre>
  
  <p>I've run out of ideas and know my coding isn't correct, especially the If/Else statement within the If/Else statement.  I also am not sure if it is better to use the "isset" to see if the cookie is being used or ($_COOKIES['variable'] == "#").  I'd really appreciate some good feedback on this one.</p>
  
  <p><strong>Thanks in advance for your help and suggestions,</strong></p>
  
  <p><strong>Matt</strong></p>