Skip to main content

A PHP function to determine if a request is accessed via an encrypted (HTTPS) connection.

<?php
  /**
   * Is HTTPS?
   *
   * Determines if the application is accessed via an encrypted
   * (HTTPS) connection.
   *
   * @return  bool
   */
  function is_https()
  {
    if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on')
    {
      return TRUE;
    }
    elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
    {
      return TRUE;
    }
    elseif (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && $_SERVER['HTTP_FRONT_END_HTTPS'] === 'on')
    {
      return TRUE;
    }
    return FALSE;
  }
?>