I know there a some questions about the subject, but they all contain different answers. I am wondering what is most efficient way to get the base url and absolute path as of 5.4 +
Absolute path: Using magic constant
define('ROOT', __DIR__); //C:\wamp\www
Alternatively write the path yourself once
define('ROOT', 'C:\wamp\www');
Final use:
require ROOT . '/blabla/test.php';
How should I receive the absolute path otherwise? What option would be most efficient unless there aren’t any better method?
About the base url, I’m not quite sure how to generate the url.
Here’s how I generally go about this.
Bear in mind I use apache locally (Windows) which can handle ‘/’ directory separators, not sure about IIS etc.
Folder structure:
index.php:
/somefolder/core/database.php:
So basically I use
dirname(__FILE__)in the index.php file. It always works for me and is my trusted way to get the correct path to the root directory.