I'm doing a small intranet site for my employer. I'm the only developer on it at this point. (Woe be unto them.) I'm still very much a noob to web development.
I'm running the dev version of this site with NetBeans as the "server" (ultimately using EasyPHP). When I run the project in NetBeans, the browser has the site root as "localhost:8000" or whatever port. Nothing wrong there. When I try to run it directly thru EasyPHP, It has "aliases" which point to specified directories on my hard drive as the site roots, so the browser says something like "127.0.0.1/Intranet/" as the site root. Unfortunately, that breaks everything in multiple ways. For one, the way I was getting the site's root:
define('WEB_ROOT', filter_input(INPUT_SERVER, 'DOCUMENT_ROOT');
define('SOURCE_ROOT', dirname(WEB_ROOT);
WEB_ROOT
ended up pointing to the directory EasyPHP is installed, rather than the directory the site is in, so naturally any includes with WEB_ROOT
in them broke. Instead, there was another $_SERVER key called 'CONTEXT_DOCUMENT_ROOT'
that points to the right place. OK, easy enough to test if that key isset()
and use it if it is, but then, the links to my css and javascript files were broken, because they were linked in my code like /js.js
with a leading slash. I thought the leading /
would automatically point to the site root, but instead it seems to point to the root in the browser, since the console said it couldn't find "127.0.0.1/js.js" when it should have been looking for "127.0.0.1/Intranet/js.js".
Does any of this make sense? What does the leading slash actually do? Should I link my css and js with my WEB_ROOT constants instead? I don't want to do it with relative paths, because (at this point) there are a lot of directories and subdirectories in this site, any of which need to find WEB_ROOT/js.js or style.css.
Although the prod version is working (it's on a different computer with different server software), these errors make me think I'm doing something wrong. Any thoughts?
Thanks!
PS. This question's answer speaks to my question somewhat, but I'm wondering if anyone can explain the forward slash further.