Adding HTTPS effectively in PHP website
<p>I'm trying to roll out HTTPS on a small website with minimal changes, I am adding code at the top of the pages I want protected...</p>

<pre><code>&lt;?php
$securepage ="1";

if ($_SERVER['HTTPS']=='on') {
    // we are on a secure page.
    if (!$securepage) {
      // but we shouldn't be!
      $url='http://www.mywebsite.com'.$_SERVER['REQUEST_URI'];
      header('location: '.$url);
      exit;
    }
  } else {
    // we aren't on a secure page.
    if ($securepage) {
      // but we should be!
      $url='https://www.mywebsite.com'.$_SERVER['REQUEST_URI'];
      header('location: '.$url);
      exit;
    }
  }
?&gt;
</code></pre>

<p>The pages I don't want protected I remove the following...</p>

<pre><code>$securepage ="1";
</code></pre>

<p>but when I try loading the page I get an error saying the page was redirected too many times.</p>

<p>Anyone have any pointers as to what is wrong with the code above?</p>
