diff --git a/public/index.php b/public/index.php index 1831b58..23830c0 100644 --- a/public/index.php +++ b/public/index.php @@ -8,14 +8,20 @@ use App\Controller\SampleFormController; /** * relative path of the index.php's directory from the server's document root. */ -global $basePath; -// find the server path of the index.php file -$basePath = dirname(substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT']))); +function get_base_path() { + // find the server path of the index.php file + $basePath = dirname(substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT']))); -if ($basePath[strlen($basePath) - 1] == "/") { - $basePath = substr($basePath, 0, strlen($basePath) - 1); + $c = $basePath[strlen($basePath) - 1]; + + if ($c == "/" || $c == "\\") { + $basePath = substr($basePath, 0, strlen($basePath) - 1); + } + return $basePath; } +$basePath = get_base_path(); + // routes initialization $router = new AltoRouter(); $router->setBasePath($basePath);