public static function phpSelf($dropqs = true)
    {
        $url = null;
        if (php_sapi_name() != 'cli') {

            $schema = 'http';
            if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) {
                $schema .= 's';
            }
            $url = sprintf('%s://%s%s', $schema, $_SERVER['SERVER_NAME'],
                $_SERVER['REQUEST_URI']);

            $parts = parse_url($url);

            $port   = $_SERVER['SERVER_PORT'];
            $scheme = $parts['scheme'];
            $host   = $parts['host'];
            if (isset($parts['path'])) {
                $path = $parts['path'];
            } else {
                $path = null;
            }
            if (isset($parts['query'])) {
                $qs = $parts['query'];
            } else {
                $qs = null;
            }
            $port || $port = ($scheme == 'https') ? '443' : '80';

            if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port
                != '80')
            ) {
                $host = "$host:$port";
            }
            $url = "$scheme://$host$path";
            if (!$dropqs) {
                return "{$url}?{$qs}";
            } else {
                return $url;
            }
        }
    }
public static function phpSelf($dropqs = true)
    {
        $url = null;
        if (php_sapi_name() != 'cli') {

            $schema = 'http';
            if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) {
                $schema .= 's';
            }
            $url = sprintf('%s://%s%s', $schema, $_SERVER['SERVER_NAME'],
                $_SERVER['REQUEST_URI']);

            $parts = parse_url($url);

            $port   = $_SERVER['SERVER_PORT'];
            $scheme = $parts['scheme'];
            $host   = $parts['host'];
            if (isset($parts['path'])) {
                $path = $parts['path'];
            } else {
                $path = null;
            }
            if (isset($parts['query'])) {
                $qs = $parts['query'];
            } else {
                $qs = null;
            }
            $port || $port = ($scheme == 'https') ? '443' : '80';

            if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port
                != '80')
            ) {
                $host = "$host:$port";
            }
            $url = "$scheme://$host$path";
            if (!$dropqs) {
                return "{$url}?{$qs}";
            } else {
                return $url;
            }
        }
    }
public static function phpSelf ( $ dropqs = true ) { $ url = null ; if ( php_sapi_name ( ) != 'cli' ) { $ schema = 'http' ; if ( isset ( $ _SERVER [ 'HTTPS' ] ) && ( $ _SERVER [ 'HTTPS' ] == 'on' ) ) { $ schema .= 's' ; } $ url = sprintf ( '%s://%s%s' , $ schema , $ _SERVER [ 'SERVER_NAME' ] , $ _SERVER [ 'REQUEST_URI' ] ) ; $ parts = parse_url ( $ url ) ; $ port = $ _SERVER [ 'SERVER_PORT' ] ; $ scheme = $ parts [ 'scheme' ] ; $ host = $ parts [ 'host' ] ; if ( isset ( $ parts [ 'path' ] ) ) { $ path = $ parts [ 'path' ] ; } else { $ path = null ; } if ( isset ( $ parts [ 'query' ] ) ) { $ qs = $ parts [ 'query' ] ; } else { $ qs = null ; } $ port || $ port = ( $ scheme == 'https' ) ? '443' : '80' ; if ( ( $ scheme == 'https' && $ port != '443' ) || ( $ scheme == 'http' && $ port != '80' ) ) { $ host = "$host:$port" ; } $ url = "$scheme://$host$path" ; if ( ! $ dropqs ) { return "{$url}?{$qs}" ; } else { return $ url ; } } }
Returns the current URL. This is instead of PHP_SELF which is unsafe.

@param bool $dropqs whether to drop the querystring or not. Default true

@return string the current URL or NULL for php-cli
Returns the current URL . This is instead of PHP_SELF which is unsafe .