get current schema from request

    0

    1

    The getCurrentSchemeFromRequestHeader() function returns the scheme from the request header 'HTTP_X_FORWARDED_SCHEME'. If the header is not set or if the header value is not a valid scheme, the function returns 'http'.

    Shortcut: url.schema

    
    /**
    * @return string eg: http https
    */
    function getCurrentSchemeFromRequestHeader()
    {
      if (isset($_SERVER['HTTP_X_FORWARDED_SCHEME']) && strtolower($_SERVER['HTTP_X_FORWARDED_SCHEME']) === 'https') {
        return 'https';
      }
    
      if (isset($_SERVER['HTTP_X_URL_SCHEME']) && strtolower($_SERVER['HTTP_X_URL_SCHEME']) === 'https') {
        return 'https';
      }
    
      if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'http') {
        return 'http';
      }
    
      if (
        (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true))
        || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
      ) {
        return 'https';
      }
      return 'http';
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.