diff --git a/common.php b/common.php index 4e97e3c10..3af8e10c0 100644 --- a/common.php +++ b/common.php @@ -66,11 +66,13 @@ $g4 = array(); function g4_path() { - $result['path'] = dirname(__FILE__); - $root = str_replace($_SERVER['DOCUMENT_ROOT'], '', $result['path']); + $result['path'] = str_replace('\\', '/', dirname(__FILE__)); + $tilde_remove = preg_replace('/^\/\~[^\/]+(.*)$/', '$1', $_SERVER['SCRIPT_NAME']); + $document_root = str_replace($tilde_remove, '', $_SERVER['SCRIPT_FILENAME']); + $root = str_replace($document_root, '', $result['path']); $port = $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : ''; $http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') ? 's' : '') . '://'; - $user = str_replace(str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']), '', $_SERVER['SCRIPT_NAME']); + $user = str_replace(str_replace($document_root, '', $_SERVER['SCRIPT_FILENAME']), '', $_SERVER['SCRIPT_NAME']); $result['url'] = $http.$_SERVER['SERVER_NAME'].$port.$user.$root; return $result; }