From e7f5cc72c5b9741fc2264e42db7965f640a5013e Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Thu, 2 Nov 2023 16:49:02 +0100 Subject: [PATCH] fix base path --- public/index.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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);