I need to find out dynamically the base url of a script. Let's say I have installed a script in the folder script, the base url of the script would be http://www.example.com/script, let's say I place it in the root it has to be http://www.example.com
Is there a way to find this out dynamically?
Using basename(__DIR__),
or basename(__FILE__)
, getcwd()
won't bring me the desired results.
Tried stuff similar to echo $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
but this of course always gives back the current page url.
I want to declare a constant called ROOT_URL in my index.php (everything gets loaded by this file), so I can use this constant in any wished project.