Err Posted November 15, 2006 Share Posted November 15, 2006 Hi.I was wondering if anyone knows an easier way to use the php include on sub-directories in a site. Currently the way I have it set up is I have 2 documents which contains links (and other content) for the site that are almost exactly the same that are called by the php, one for the main directory (./) and another for the sub-directory, (./subdir/) both of which are located on the main directory, the only difference between the 2 documents are in the relative links where I would have to put ../ to reference back to the main directory (e.g. ../main.php) while the other document could stay at ./ or just the regular main.php. I know I could have one document and have just ../, where it would link back to the main directory regardless, but I don't want to do that as if I wanted to add another sub sub-directory I would have to add ../../ to the links in it again; I'm not willing to do that each time, as it's not practical. Do you understand what I'm trying to say? So is there an easier way of doing this without having to have 2 separate documents? My goal is to only have 1 document which the php calls for every time without any relative linking problems.Thanks for reading. Link to comment Share on other sites More sharing options...
jesh Posted November 15, 2006 Share Posted November 15, 2006 I know in javascript, HTML, and ASP.NET (C#), you can reference the root directory by placing a "/" in front of it (no dots).So, if you had a root directory and two sub directories - sub1 and sub2 - and you needed to link to a file - main.php - in an include that was on files on all three of those directories, rather than using "./", "../", etc, you should be able to use "/main.php" and they will look for "main.php" in your root directory./ = root directory./ = current directory../ = parent directoryI'm not sure if this is the same with PHP or not, but it's worth a shot. Link to comment Share on other sites More sharing options...
reportingsjr Posted November 15, 2006 Share Posted November 15, 2006 Indead it is, you can just do /directory/directory/page.php and it will work. So the root is / . Link to comment Share on other sites More sharing options...
justsomeguy Posted November 15, 2006 Share Posted November 15, 2006 Don't use relative links at all. If you are planning on moving the application to a different location, or selling or distributing it, then save the location in a global variable and use the global variable in all of your links. global $HTTP_SYSTEM_PATH;$HTTP_SYSTEM_PATH = "http://www.domain.com/dir1/dir2/";...<a href="<?php echo $HTTP_SYSTEM_PATH; ?>menu.php">...</a><a href="<?php echo $HTTP_SYSTEM_PATH; ?>subdir/file.php">...</a> Link to comment Share on other sites More sharing options...
Err Posted November 16, 2006 Author Share Posted November 16, 2006 Thanks a lot! It works just fine now. Thanks for all your suggestions. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now