include() and absolute path

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

Threaded View

I am setting up a website with a number of folders like:
/ (the document root)
in the /user  folder there is a flie "userlogged.php", which I want to
include in every file. If in the file "/content/index.php", if I use
the relative path and place the include like this
"../user/userlogged.php", it will work fine. But when I use the
absolute path like "/user/userlogged.php", it is not working ?. I have
read in several posts that the absolute path will work with include().
( Or am I wrong ?)
can any body tell me how to enable the absolute path method ?. The
relative path method is fine but when going deep with many subfolders,
the path will be come lengthy with "../../" and is difficult to
maintain and is a problem when moving the pages around. using absolute
path is a remedy to this.

is there any other method/ function similar to include(), to place
content of a file in another file ?

thanks ina dvance.

Raju V.K.

Re: include() and absolute path

When you use include("/mypath/myfile.php") it doesnt look in the path
relative to / but rather relative to your system root.
 You can make a .htaccess file that looks like this:
php_flag  include_path "/home/me/myphpfiles/:."

And do include("user/userlogged.php") and will then first look for
/home/me/myphpfiles/user/userlogged.php, if it's not found, it will be
looked for relative to the current path.

Re: include() and absolute path

Does the PHP and HTML behave differently when  it comes to paths ?. If
I give /user/userlogged.php as the address of a page in the <a></a>
tag, it will always loads the userlogged.php page from the /user
folder, from the document root of the web-site. (That is ). I wish to repeat this behaviour
in PHP include(). Irrespectice of the location of the file calling the
include function, the page userlogged.php shall be included. What is
the best way to achieve this ?


Re: include() and absolute path wrote:
Quoted text here. Click to load it

   I'm afraid, it is very hard to help you here--you seem to lack the
basic idea of filesystems. You definitely have to look at file system
basics and HTTP basics.

  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: /

Site Timeline