title: how to redirect page to https in php?
body: <p>i have a login form:</p>
  
  <pre><code>&lt;form method =POST action="/login.php"&gt;
  ...
  &lt;/form&gt;
  </code></pre>
  
  <p>i would like the <code>login.php</code> page to redirect to using <code>https</code>.</p>
  
  <p>i don't want to send the user to <code>https://.../login.php</code> because they might change the link. but i want to do a redirect on the server side before i parse the login form data and log the user in.</p>
  
  <p>i found and example:</p>
  
  <pre><code>if($_SERVER["HTTPS"] != "on") {
     header("HTTP/1.1 301 Moved Permanently");
     header("Location: "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
     exit();
  }
  </code></pre>
  
  <p>but i don't have <code>$_SERVER["HTTPS"]</code> if i <code>var_dump($_SERVER);</code></p>
  
  <p>i do have <code>$_SERVER['SERVER_PORT']</code> witch is 80.</p>
  
  <p>any ideas?</p>
  
  <p>Thanks</p>