title: Require cookie to view website, or be redirected to different page (PHP)
body: <p>Simple request; I need visitors to my site to have a certain cookie to view the website. When user goes to <strong><em>my.site.com/anydirectory/anypage.php</em></strong> they need to be redirected to <strong><em>my.site.com/index.php</em></strong> where they are given a warning and a choice to <strong>Walk Away</strong> or <strong>Continue</strong>. If they Continue, a cookie is set and they are take to the originally requested page (and ultimately have access to the whole site, for at least 90 days). If they choose to Walk Away then a different cookie is set and they are redirected to <strong><em>my.site.com/bummer.php</em></strong>, and will continue to be directed to the <strong>bummer.php</strong> page until 90 days is up or they delete the cookie, whichever comes first.</p>
  
  <p>Here is what I have;</p>
  
  <p>I placed this at the top of all of my pages...</p>
  
  <pre><code>&lt;?php if (!isset($_COOKIE['youwerewarned'])) {
  header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")
  }
  ?&gt;
  </code></pre>
  
  <p>...then I placed this at the top of my <strong>index.php</strong> page...</p>
  
  <pre><code>&lt;?php
  
  // change to your domain name.
  $domain = "my.site.com";
  
  // Get the requested page, add it to our domain so we can create an enter link
  if (isset($_GET['request'])) {
  $request ="&lt;a href='http://$domain" . $_GET['request'] . "'&gt;";
  }
  
  // The exit link
  {
  $leave ="&lt;a href='http://my.site.com/bummer.php'&gt;";
  }
  
  // Set a cookie so we are not redirected back here again. You can set how long the cookie is good.
  if (!isset($_COOKIE['youwerewarned'])) {
  setcookie('youwerewarned','true',time()+6048... . $domain);
  }
  
  ?&gt;
  </code></pre>
  
  <p>...then I placed this in the <strong>index.php</strong> page in the appropriate place...</p>
  
  <pre><code>&lt;?php echo $leave ?&gt;WALK AWAY&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;?php echo $request ?&gt;CONTINUE&lt;/a&gt;
  </code></pre>
  
  <p>...what am I missing?</p>