On my local site, $_SERVER[‘DOCUMENT_ROOT’] returns C:/xampp/htdocs. Shouldn’t it also add /mysite?
My includes work when I do this:
include $_SERVER[‘DOCUMENT_ROOT’].‘/mysite/includes/myfunctions.php’;
But won’t that cause a problem when I publish my site? I didn’t think that /mysite should be in the include.
If this is a problem, how do I fix it?
Robert
This is a common issue, and its solution depends on your application architecture.
Document Root is not the path to your project directory, its the path to the server base directory - i.e. the directory that http://localhost/ maps to.
My typical application works by routing every request to index.php. Therefore I simply use DIR in index.php to get the root.
Would it not make more sense to use a relative path?
What’s the document root specified in your httpd.conf/httpd-vhosts.conf? That’s the document root, it’s not an alias for the current directory.
I always have some kind of front controller or dispatcher in my applications, so that’s where I define the root using dirname(FILE), so it’s relative to the front controller.