Get the current url based on $_SERVER

by http://www.webcheatsheet.com/PHP/get_current_page_url.php

@return [type] [description]
346343
public static function get_realCurrentUrl()
    {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://".$_SERVER["SERVER_NAME"];
        if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= ':' . $_SERVER["SERVER_PORT"];
        }
        $pageURL .= $_SERVER["REQUEST_URI"];
        return $pageURL;
    }
983600
protected function getCurrentUrl()
    {
        $schema = ((!empty($this->server['HTTPS']) && $this->server['HTTPS'] !== 'off') || (!empty($this->server['SERVER_PORT']) && $this->server['SERVER_PORT'] == 443)) ? 'https://' : 'http://';

        $host = isset($this->server['HTTP_HOST']) ? $this->server['HTTP_HOST'] : 'localhost';

        return $schema.$host.$this->server['REQUEST_URI'];
    }
455800
public function getUrl()
    {
        if (empty($this->url)) {
            $url = $this->httpRequest()->getCurrentUrl(true)->getPath();
            // we need to have the trailing slash because of the match inside matchRequest
            // and also when matching the default method, we can do an incorrect match if we don't have the start and end slash
            $this->url = $this->str($url)->trimRight('/')->val() . '/';
        }

        return $this->url;
    }
365910
public static function getBaseUrl()
    {
        $protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http';
        $url = $protocol . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];

        // cut at last '/' (we dont want to see index.php)
        return substr($url, 0, strrpos($url, '/'));
    }
159411
public static function get_currentUrl($filter = array(), $queryFilter = array(), $queryFilterMethod = 'remove')
    {
        if (!is_array($filter) && !empty($filter)) {
            $filter = array($filter);
        }

        if (!empty(self::$fakeCurrentUrl)) {
            $pageURL = self::$fakeCurrentUrl;
        } else {
            $pageURL = self::get_realCurrentUrl();
        }

        if (empty($filter) && empty($queryFilter)) {
            return $pageURL;
        }

        if (empty($filter)) {
            $filter = array('http', 'name', 'port', 'path', 'request');
        }

        $urlParts = parse_url($pageURL);

        if (!in_array('http', $filter)) {
            $pageURL = preg_replace('#.*://#', '', $pageURL);
        }

        if (!in_array('name', $filter) && !in_array('host', $filter) && array_key_exists('host', $urlParts)) {
            $pageURL = str_replace($urlParts['host'], '', $pageURL);
        }

        if (!in_array('port', $filter) && array_key_exists('port', $urlParts)) {
            $pageURL = str_replace(':'.$urlParts['port'], '', $pageURL);
        }
        
        if (!in_array('path', $filter) && array_key_exists('path', $urlParts)) {
            $pageURL = str_replace($urlParts['path'], '', $pageURL);
        }

        if ((in_array('request', $filter) || in_array('query', $filter)) && array_key_exists('query', $urlParts)) {
            if (!empty($queryFilter) && is_array($queryFilter)) {
                parse_str($urlParts['query'], $query);
                

                self::filter_data($query, $queryFilter, $queryFilterMethod);

                $pageURL = explode('?', $pageURL);

                if (empty($query)) {
                    unset($pageURL[1]);
                } else {
                    $pageURL[1] = http_build_query($query);
                }

                $pageURL = implode('?', $pageURL);
            }
        } else {
            $pageURL = preg_replace('/\?.*/', '', $pageURL);
        }

        return $pageURL;
    }
438337
public static function currentPage() {
		$uri = static::to(static::detectPath());
		foreach ($_GET as $k => $v) {
			$uri->param($k, $v);
		}

		return $uri;
	}
871026
public static function currentServerName()
    {
        if (! empty(env('SERVER_NAME'))) {
            $BASE_URL = env('SERVER_NAME');
        } elseif (! empty($_SERVER['SERVER_NAME'])) {
            $BASE_URL = $_SERVER['SERVER_NAME'];
        } elseif (! empty($_SERVER['HTTP_HOST'])) {
            $BASE_URL = $_SERVER['HTTP_HOST'];
        } else {
            $BASE_URL = 'empty';
        }
        return $BASE_URL;
    }
862051
public function getCurrentUrl()
    {
        $oUtilsServer = \OxidEsales\Eshop\Core\Registry::getUtilsServer();

        $aServerParams["HTTPS"] = $oUtilsServer->getServerVar("HTTPS");
        $aServerParams["HTTP_X_FORWARDED_PROTO"] = $oUtilsServer->getServerVar("HTTP_X_FORWARDED_PROTO");
        $aServerParams["HTTP_HOST"] = $oUtilsServer->getServerVar("HTTP_HOST");
        $aServerParams["REQUEST_URI"] = $oUtilsServer->getServerVar("REQUEST_URI");

        $sProtocol = "http://";

        if (isset($aServerParams['HTTPS']) && (($aServerParams['HTTPS'] == 'on' || $aServerParams['HTTPS'] == 1))
            || (isset($aServerParams['HTTP_X_FORWARDED_PROTO']) && $aServerParams['HTTP_X_FORWARDED_PROTO'] == 'https')
        ) {
            $sProtocol = 'https://';
        }

        return $sProtocol . $aServerParams['HTTP_HOST'] . $aServerParams['REQUEST_URI'];
    }
777410
static function get_current_page() {
            if ( ! isset( self::$_pagenow ) ) {
                global $pagenow;
                if ( empty( $pagenow ) && is_admin() && is_multisite() ) {
                    /**
                     * It appears that `$pagenow` is not yet initialized in some network admin pages when this method
                     * is called, so initialize it here using some pieces of code from `wp-includes/vars.php`.
                     *
                     * @author Leo Fajardo (@leorw)
                     * @since 2.2.3
                     */
                    if ( is_network_admin() ) {
                        preg_match( '#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    } else if ( is_user_admin() ) {
                        preg_match( '#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    } else {
                        preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
                    }

                    $pagenow = $self_matches[1];
                    $pagenow = trim( $pagenow, '/' );
                    $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
                    if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
                        $pagenow = 'index.php';
                    } else {
                        preg_match( '#(.*?)(/|$)#', $pagenow, $self_matches );
                        $pagenow = strtolower( $self_matches[1] );
                        if ( '.php' !== substr($pagenow, -4, 4) )
                            $pagenow .= '.php'; // for Options +Multiviews: /wp-admin/themes/index.php (themes.php is queried)
                    }
                }

                self::$_pagenow = $pagenow;

                if ( self::is_ajax() &&
                     'admin-ajax.php' === $pagenow
                ) {
                    $referer = fs_get_raw_referer();

                    if ( is_string( $referer ) ) {
                        $parts = explode( '?', $referer );

                        self::$_pagenow = basename( $parts[0] );
                    }
                }
            }

            return self::$_pagenow;
        }
1083425
public static function url()
    {

        $server = $_SERVER;

        $ssl = (!empty($server['HTTPS']) && $server['HTTPS'] == 'on');

        $sp = strtolower($server['SERVER_PROTOCOL']);

        $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');

        $port = $server['SERVER_PORT'];

        $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port;

        $host = isset($host) ? $host : $server['SERVER_NAME'] . $port;

        $host .= preg_replace("/\?.*/", "", $server["REQUEST_URI"]);

        return $protocol . '://' . $host;
    }
266408
private function _getClientUrl()
    {
        $server_url = '';
        if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
            // explode the host list separated by comma and use the first host
            $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_HOST']);
            // see rfc7239#5.3 and rfc7230#2.7.1: port is in HTTP_X_FORWARDED_HOST if non default
            return $hosts[0];
        } else if (!empty($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
            $server_url = $_SERVER['HTTP_X_FORWARDED_SERVER'];
        } else {
            if (empty($_SERVER['SERVER_NAME'])) {
                $server_url = $_SERVER['HTTP_HOST'];
            } else {
                $server_url = $_SERVER['SERVER_NAME'];
            }
        }
        if (!strpos($server_url, ':')) {
            if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) {
                $server_port = $_SERVER['SERVER_PORT'];
            } else {
                $ports = explode(',', $_SERVER['HTTP_X_FORWARDED_PORT']);
                $server_port = $ports[0];
            }

            if ( ($this->_isHttps() && $server_port!=443)
                || (!$this->_isHttps() && $server_port!=80)
            ) {
                $server_url .= ':';
                $server_url .= $server_port;
            }
        }
        return $server_url;
    }
159609
protected function currentUrlHost()
    {
        if (isset(static::$static[__FUNCTION__])) {
            return static::$static[__FUNCTION__];
        }
        if (!empty($this->options['current_url_host'])) {
            return static::$static[__FUNCTION__] = $this->nUrlHost($this->options['current_url_host']);
        }
        if (empty($_SERVER['HTTP_HOST'])) {
            throw new \Exception('Missing required `$_SERVER[\'HTTP_HOST\']`.');
        }
        return static::$static[__FUNCTION__] = $this->nUrlHost($_SERVER['HTTP_HOST']);
    }
1051084
public function getCurrentUrl(): string
    {
        /** @var WP $wp */
        $wp = Core::get(WP::class);
        return $this->wpProvider->homeUrl(
            $this->wpProvider->addQueryArg([], $wp->request));
    }
1330457
public function getBaseUrl()
    {
        if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST'])) {
            $base_url = ($this->isSecure() ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']
            . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
        } else {
            $base_url = 'http://localhost/';
        }

        return rtrim($base_url, '/') . '/';
    }
830719
public static function getCurrentURL()
    {
        $url = 'http://';
        if (self::isHttps()) {
            $url = 'https://';
        }

        if (isset($_SERVER['PHP_AUTH_USER'])) {
            $url .= $_SERVER['PHP_AUTH_USER'];
            if (isset($_SERVER['PHP_AUTH_PW'])) {
                $url .= ':'.$_SERVER['PHP_AUTH_PW'];
            }
            $url .= '@';
        }
        if (isset($_SERVER['HTTP_HOST'])) {
            $url .= $_SERVER['HTTP_HOST'];
        }
        if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) {
            $url .= ':'.$_SERVER['SERVER_PORT'];
        }
        if (!isset($_SERVER['REQUEST_URI'])) {
            $url .= substr($_SERVER['PHP_SELF'], 1);
            if (isset($_SERVER['QUERY_STRING'])) {
                $url .= '?'.$_SERVER['QUERY_STRING'];
            }

            return $url;
        }

        $url .= $_SERVER['REQUEST_URI'];

        return $url;
    }
1355882
private static function getUrlQueryString() {
        // The variable $_SERVER['QUERY_STRING'] is set by the server and can differ, e.g. it might hold additional
        // parameters or it might be empty (nginx).

        if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING'])) {
            $query = $_SERVER['QUERY_STRING'];
        }
        else {
            $query = strRightFrom($_SERVER['REQUEST_URI'], '?');
        }
        return $query;
    }
955655
protected function calculateCurrentURL()
    {
        $url = "http";
        if ($this->isSecureConnection()) {
            $url .= 's://' . $_SERVER['SERVER_NAME'] . ('443' != $_SERVER['SERVER_PORT'] ? ':' . $_SERVER['SERVER_PORT'] : '');
        } else {
            $url .= '://' . $_SERVER['SERVER_NAME'] . ('80' != $_SERVER['SERVER_PORT'] ? ':' . $_SERVER['SERVER_PORT'] : '');
        }
        $this->host = $_SERVER['SERVER_NAME'];
        $this->currentDomain = $url . '/';
        $this->currentURL = $url . $_SERVER['REQUEST_URI'];
        if ($_SERVER['DOCUMENT_ROOT'][strlen($_SERVER['DOCUMENT_ROOT']) - 1] == '/') {
            $docRoot = substr($_SERVER['DOCUMENT_ROOT'], 0, strlen($_SERVER['DOCUMENT_ROOT']) - 1);
        } else {
            $docRoot = $_SERVER['DOCUMENT_ROOT'];
        }
        $secondPart = str_replace($docRoot, '', dirname($_SERVER['SCRIPT_FILENAME'])) . '/';
        $this->baseURL = $url . (('/' == $secondPart[0]) ? $secondPart : '/' . $secondPart);
    }