This is a discussion on include() and absolute path within the PHP Language forums, part of the PHP Programming Forums category; I am setting up a website with a number of folders like: / (the document root) /user /admin/ /content in the /...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
rajuvk@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/ |