directory does this work?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
In ASP/IIS if I want to point to a folder/directory in the root as an
in include I write this...

<!--#include virtual="/menu.asp" -->

In PHP/Apache I have to do this...
<?php include "menu.php" ?> or something like this....

My problem is in asp I can reference this file from any
folder/directory.  For example, if I were here.... "/admin/default.asp"
I could reference the include as is.  In php I can't do this, at least
I don't know how to.  Another problem is that if there are file paths
in the include itself this problem comes up again.  I know I could
write this <?php include "../menu.php"?>  and it would find it's way to
the file but what about the file paths in the include?  This is a menu
with relative paths to images.

How can I point at a file in the root from any directory in my website
using a relative path?  I know I should probably avoid an http://


Re: directory does this work?

Quoted text here. Click to load it

PHP has a configuration setting include_path.
Apart from setting it in php.ini you can also change it at runtime
( ).
And you can manipulate it with and

The only problem you might experience is that paths are separated with ; on
windows platforms and with : on unix platforms. To avoid this i suggest you take
an approach as following:

$include_paths = array('.', '..', '/var/somewhere' , get_include_path());
ini_set('include_path', implode(PATH_SEPARATOR, $include_paths));

Met vriendelijke groeten,
Tim Van Wassenhove <

Re: directory does this work?

John K wrote:
Quoted text here. Click to load it

Check out $_SERVER['DOCUMENT_ROOT'].  It always points to the root  
directory of your web site, no matter where that is.

You could, for instance, do something like:

   <?php include($_SERVER['DOCUMENT_ROOT'] . '/include/menu.php'); ?>

or similar.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: directory does this work?

As it's turning out this entire problem "isn't" a problem on the live
server.  I'm using XAMPP to develop locally and it appears this problem
is coming from there?  I haven't throughly tested on the live server
yet but someone demonstrated to me that the absolute paths "do" work
there, they just don't on XAMPP.  It may yet turn out to no be this
simple but we'll see.

Are there any XAMPP experts out there?

Site Timeline