By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

include() and absolute path

P: n/a
I am setting up a website with a number of folders like:
/ (the document root)
/user
/admin/
/content
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.

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
When you use include("/mypath/myfile.php") it doesnt look in the path
relative to http://mysite.com/ 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.

Jul 17 '05 #2

P: n/a
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
http://mysite.com/user/userlogged.php). 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 ?

Regards,
Raju

Jul 17 '05 #3

P: n/a
ra****@satyam.net.in wrote:
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
http://mysite.com/user/userlogged.php). 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 ?


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: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.