[thelist] PHP, include() and relative links

Michael Wolfe wolfboy69 at earthlink.net
Fri May 25 12:18:32 CDT 2001


At 05:40 PM 5/25/01 +0100, you wrote:
>Could anyone tell me how to use absolute roots - if that's the right way of
>putting it - and the include command in PHP, or am I trying to do the
>impossible.
>
>I want to be able to include a file called template.php located in a files
>directory. I want this file to be included by several different files held
>in different directories. I thought this could be acheived using
>include("/file/template.php") but it doesn't seem to want to work.

Peter,

What I usually do is declare a variable that points to DOCUMENT_ROOT in a 
file called globals.php, which I include with every file.

here's the code snippet

<?php
$DR = $DOCUMENT_ROOT;
?>

Here's the line I include in all of my files:

<?php
include($DOCUMENT_ROOT."/inc/globals.php");
?>


And then, when I want to use absolute references, I use something like this:
<?php
include($DR."/inc/db.inc.php");
?>




___________________
Michael Wolfe
Senior Software Engineer

http://www.ework.com
mwolfe at ework.com






More information about the thelist mailing list