title: Php https request for a page
body: <p>I was trying to use this code: </p>
  
  <pre><code>if($_SERVER['HTTP_PORT'] !== 443 &amp;&amp; !isset($_SERVER['HTTPS'])) {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
  }
  </code></pre>
  
  <p>to make my login page and register page contain <strong>https</strong> to use the ssl to make sure that everything is secure, but when I run the page an error message shows up <strong>Undefined index error using $_SERVER['HTTPS']</strong></p>
  
  <p>so I decided to use another one:</p>
  
  <pre><code>if ( isset( $_SERVER["HTTPS"] ) &amp;&amp; strtolower( $_SERVER["HTTPS"] ) == "on" ) {
    $pageURL .= "s";
  }
  </code></pre>
  
  <p>but it didn't work. The https didn't show up and http is only there...</p>
  
  <p>any idea how to do that with php...</p>
  
  <p>Thanks</p>
  
  <p><strong>The solution is:</strong></p>
  
  <pre><code>if($_SERVER["HTTPS"] != "on")
  </code></pre>
  
  <p><code>{
      header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
      exit();
  }</code></p>