How to redirect to a secure connection

Index Description
HTTPS Returns a non-empty value if the current request is using HTTPS.
HTTP_HOST Returns the host for the current request.
REQUEST_URI Returns the URI (Uniform Resource Identifier) for the current request.

A utility file (util/secure_conn.php) that redirects a page to a secure connection

      <?php
      // make sure the page uses a secure connection 
      $https = filter_input(INPUT_SERVER, 'HTTPS'); 
      if (!$https) { 
        $host = filter_input(INPUT_SERVER, 'HTTP_HOST'); 
        $uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
        $url = 'https://' . $host . $uri; header("Location: " . $url); 
        exit(); 
      } 
      ?>
      

Description

Back