src/Core/LTIX.php
public static function curPageUrlBase() {
        global $CFG;

        $pieces = parse_url($CFG->wwwroot);

        if ( isset($pieces['scheme']) ) {
            $scheme = $pieces['scheme'];
        } else {
            $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
                ? 'http' : 'https';
        }

        if ( isset($pieces['port']) ) {
            $port = ':'.$pieces['port'];
        } else {
            $port = '';
            if ( $_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" &&
                strpos(':', $_SERVER['HTTP_HOST']) < 0 ) {
                $port =  ':' . $_SERVER['SERVER_PORT'] ;
            }
        }
        $host = isset($pieces['host']) ? $pieces['host'] : $_SERVER['HTTP_HOST'];

        $http_url = $scheme .  '://' . $host .  $port;
        return $http_url;
    }
public static function curPageUrlBase() {
        global $CFG;

        $pieces = parse_url($CFG->wwwroot);

        if ( isset($pieces['scheme']) ) {
            $scheme = $pieces['scheme'];
        } else {
            $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
                ? 'http' : 'https';
        }

        if ( isset($pieces['port']) ) {
            $port = ':'.$pieces['port'];
        } else {
            $port = '';
            if ( $_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" &&
                strpos(':', $_SERVER['HTTP_HOST']) < 0 ) {
                $port =  ':' . $_SERVER['SERVER_PORT'] ;
            }
        }
        $host = isset($pieces['host']) ? $pieces['host'] : $_SERVER['HTTP_HOST'];

        $http_url = $scheme .  '://' . $host .  $port;
        return $http_url;
    }
public static function curPageUrlBase ( ) { global $ CFG ; $ pieces = parse_url ( $ CFG -> wwwroot ) ; if ( isset ( $ pieces [ 'scheme' ] ) ) { $ scheme = $ pieces [ 'scheme' ] ; } else { $ scheme = ( ! isset ( $ _SERVER [ 'HTTPS' ] ) || $ _SERVER [ 'HTTPS' ] != "on" ) ? 'http' : 'https' ; } if ( isset ( $ pieces [ 'port' ] ) ) { $ port = ':' . $ pieces [ 'port' ] ; } else { $ port = '' ; if ( $ _SERVER [ 'SERVER_PORT' ] != "80" && $ _SERVER [ 'SERVER_PORT' ] != "443" && strpos ( ':' , $ _SERVER [ 'HTTP_HOST' ] ) < 0 ) { $ port = ':' . $ _SERVER [ 'SERVER_PORT' ] ; } } $ host = isset ( $ pieces [ 'host' ] ) ? $ pieces [ 'host' ] : $ _SERVER [ 'HTTP_HOST' ] ; $ http_url = $ scheme . '://' . $ host . $ port ; return $ http_url ; }
curPageUrlBase - Returns the protocol, host, and port for the current URL

This is useful when we are running behind a proxy like ngrok
or CloudFlare.  These proxies will accept with the http or
https version of the URL but our web server will likely only
se the incoming request as http.  So we need to fall back
to $CFG->wwwroot and reconstruct the right URL from there.
Since the wwwroot might have some of the request URI, like

http://tsugi.ngrok.com/tsugi

We need to parse the wwwroot and put things back together.

URL                              Result
http://x.com/data                http://x.com
http://x.com/data/index.php      http://x.com
http://x.com/data/index.php?y=1  http://x.com

@return string The current page protocol, host, and optionally port URL
curPageUrlBase - Returns the protocol host and port for the current URL