I use $_SERVER[DOCUMENT_ROOT] a lot to make sure that all my links will work properly. For instance:
<link href="' . $_SERVER[DOCUMENT_ROOT] . '/favicon.ico" rel="icon" />
It doesn't matter the actual path of the file that's in, it will always find the correct location of the favicon relative to the document root.
This all works as expected on my web server. However, on my local development server (Windows 7, Apache 2.2, virtual hosts configured), while it points to the correct path (C:/Local/MySite), nothing actually happens (favicon doesn't work, stylesheets and images don't get loaded, etc.)
Is there any way of getting $_SERVER[DOCUMENT_ROOT] to work locally?
I found that I can get the same expected result by using "http://" and $_SERVER[HTTP_HOST] (<link href="http://' . $_SERVER[HTTP_HOST] . '/favicon.ico" rel="icon" />), is there any downside to doing that? Alternatively, I can continue to use $_SERVER[DOCUMENT_ROOT] and just use server rewrite rules to parse it into something that will run locally, and leave it untouched for the browser.