PHP Includes folder, now working in sub folder

3 replies
Hi all,

I have a little question for programmers about PHP includes folder.

I am new to using PHP includes thingy, so what happened was; I setup my website using PHP includes folder and in that folder, I placed few banners and footer navigation files be called on every page.

But when I added a directory/folder on my domain, things started to get all messed up. The directory/folder I made is not fetching any footer and banners I have placed in the root includes folder. So I pasted the same includes folder in every new directory/folder I made for my site. But I am sure this is not the way it works.

Simple example of what I did:

- PHP includes placed on the root domain: www.mydomain.com - Things are working fine here and everything from the includes is showing on web pages.

- When I made a folder on my domain: www.mydomain.com/folder/ - HTML/PHP files in this new folder are not showing/fetching includes files.

Please tell me how this can be used professionally.

Also, is there any possibility that I can use a WEB URL in new folders to show includes folder data; like: "www.mydomain.com/includes/"
#call #files #folder #includes #php #url #web #working
  • Profile picture of the author patey88
    If you want pages in www.mydomain.com/folder to include files located in www.mydomain.com, then you have to reference them as ../includedfile.php for example.

    If you just put includedfile.php without the ../ it won't know the included file is really located in the root folder rather than the same folder as the page.
    {{ DiscussionBoard.errors[5085420].message }}
    • Profile picture of the author biznics
      Originally Posted by patey88 View Post

      If you want pages in www.mydomain.com/folder to include files located in www.mydomain.com, then you have to reference them as ../includedfile.php for example.

      If you just put includedfile.php without the ../ it won't know the included file is really located in the root folder rather than the same folder as the page.

      Thanks mate.

      So simply by placing two dots (../includes), I can tell the folder to get files from the root?
      {{ DiscussionBoard.errors[5085472].message }}
      • Profile picture of the author Brandon Tanner
        Originally Posted by biznics View Post

        Thanks mate.

        So simply by placing two dots (../includes), I can tell the folder to get files from the root?
        The 2 dots just represent going one folder up, which is not necessarily the root folder (although it sounds like it is in your case). Also, you can't 'include' an entire folder per se... you have to include each file in that folder individually.

        So if you want to reference a folder one directory up, then do this...

        <? php include "../foldername/filename.php" ; ?>

        But if you want to reference a folder that is in the root directory, you can do this...

        <? php include $_SERVER['DOCUMENT_ROOT'] . "/foldername/filename.php" ; ?>

        Of course, if your root folder is just 1 directory up (as it sounds like it is in your case), then the 2 examples I showed above will have the same results.
        Signature

        {{ DiscussionBoard.errors[5087994].message }}

Trending Topics