Jump to content

Include from another folder


elmas156

Recommended Posts

I have a site that I have the same information on several pages in different folders.  Right now I have an include page in each folder and when I need to change the information on the include page, I have to do it for every folder, even though the information is all the same.  What I need to do is have one include page that I can modify and all the other pages in the different folders can include it.  I know I'm kind of rambling here but I hope I'm making sense.  I need to know how to include a file from one folder into a page from another folder.  Here's what I've tried so far and it didn't work... not sure what else to try.

 

include("http://www.website.com/include.inc.php");

 

The file that I'm trying to include this into is located at http://www.website.com/folder1/page.php ...

 

so include("include.inc.php") won't work... I have to specify what folder or directory to pull the include file from.

 

Sorry about the rambling and thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/220585-include-from-another-folder/
Share on other sites

I figured it out! For those of you who may be having the same problem, here's the answer:

 

I have no idea why this isn't working:

 

include("http://www.website.com/include.inc.php");

 

But... this works fine:

 

include("../include.inc.php");

 

Basically, for each "../" you put in front of the file name, it goes up one level.  So if you're include file is located at "http://www.website.com/include.inc.php" and the page you are including it on is at "http://www.website.com/folder1/folder2/page.php" you would do this:

 

include("../../include.inc.php");

 

Hope this helps someone.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.