Changing the site root?

Okay, so we’re running Apache on a shared hosting server, along with Perl and PHP. But since it’s shared, I don’t have access to the global configuration files of these services. Right now, my site is located at:


There are certain parts of my site that will remain constant across a large subset of pages, like my header and footer. I’d like to place these into each page by using a PHP include directive, like:

<? include("/templates/banner.php") ?>

The only problem here is that “/” is interpreted to be the server root “/”, not the site root “/home/.servername/username/”, as I’d prefer. Some people have suggested using PHP’s $DOCUMENT_ROOT environment variable, but that seems like a kludge. I’d really prefer to tell Apache directly to rewrite my site root accordingly, say, by using the DocumentRoot directive.

Is there anything I can do, or do I need to resort to a hackish solution? Any help would be greatly appreciated. Thanks!

Edited: re-written totally.

This is to be expected because the PHP include function is designed to work with file system paths and does not have anything to do with document root. You can read the documentation on this function at PHP Manual - include() function

That’s one for the wastebasket. What you want to do is determine the location of the files to be included on the file-system. Now, you can hard-code an absolute path:

And if you want to leave out the /home/username, try this instead:

Or, if the file is located in beneath the document root, take advantage of $_SERVER[‘DOCUMENT_ROOT’]:

Also, you can try specifying your own php.ini file that sets include_path to the directories you want the include function to search files in.

PS. A file system is used to orgnaze files and directories on disk, thus a file system path is the path to a file or directory on disk. Thus a leading slash on a file system path maps to the root of the file system.

:cool: Perl / MySQL / HTML CSS