public static function URLfromPath($path, array $vars = null, $basePath = false)
    {
        if ($vars === null) {
            if (php_sapi_name() != 'cli') {
                $vars = $_SERVER;
            } else {
                return false;
            }
        }

        if ($basePath !== false && substr($path, 0, 1) !== '/') {
            $basePath = rtrim($basePath, '/');
            $path = realpath("$basePath/$path");
        }

        if (realpath($path)) {
            return (!isset($vars['HTTPS']) || $vars['HTTPS'] != 'on' ?
                        'http://' :
                        'https://'
                ) .
                $vars['SERVER_NAME'] .
                $vars['CONTEXT_PREFIX'] .
                str_replace(
                    $vars['CONTEXT_DOCUMENT_ROOT'],
                    '',
                    $path
                );
        } else {
            return false;
        }
    }