// 800webRoot
function _detect_webroot()
\{
    // Note for Windows users: the below assumes that your PHP_SELF variable
    // uses forward slashes. If it does not, you'll have to tweak this.
    if (isset($_SERVER['SCRIPT_URL']) || isset($_SERVER['SCRIPT_NAME'])) \{
        $path = empty($_SERVER['SCRIPT_URL']) ?
            $_SERVER['SCRIPT_NAME'] :
            $_SERVER['SCRIPT_URL'];
        $hordedir = str_replace(DIRECTORY_SEPARATOR, '/', __FILE__);
        $hordedir = basename(preg_replace(';/config/registry.php$;', '', $hordedir));
        if (preg_match(';/' . $hordedir . ';', $path)) \{
            $webroot = preg_replace(';/' . $hordedir . '.*;', '/' . $hordedir, $path);
        \} else \{
            $webroot = '';
        \}
    \} elseif (isset($_SERVER['PHP_SELF'])) \{
        $webroot = preg_split(';/;', $_SERVER['PHP_SELF'], 2, PREG_SPLIT_NO_EMPTY);
        $webroot = strstr(dirname(__FILE__), DIRECTORY_SEPARATOR . array_shift($webroot));
        if ($webroot !== false) \{
            $webroot = preg_replace(array('/\\\\/', ';/config$;'), array('/', ''), $webroot);
        \} elseif ($webroot === false) \{
            $webroot = '';
        \} else \{
            $webroot = '/horde';
        \}
    \} else \{
        $webroot = '/horde';
    \}
    
    return $webroot;
\}

