+ Reply to Thread
Results 1 to 9 of 9

Thread: No includes on higher directories?

  1. #1
    wesley09 is offline x10Hosting Member wesley09 is an unknown quantity at this point
    Join Date
    Mar 2009
    Location
    Virginia
    Posts
    5

    No includes on higher directories?

    Need to Know:
    http://example.pcriot.com/a/includes/header.php (Would contain the header)
    http://example.pcriot.com/a/includes/footer.php (Would contain the footer)
    http://example.pcriot.com/a/index.php (The index page of directory A)
    http://example.pcriot.com/a/lettera/index.php (Another index of a higher directory)

    The Problem:
    Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text.

    Example:
    Let's say I make a page with a url of http://example.pcriot.com/a/lettera/index.php.
    And I want to include http://example.pcriot.com/a/includes/header.php and http://example.pcriot.com/a/includes/footer.php
    So, I would use the PHP include function and use those.
    The problem is, the includes won't show up, just the page of /a/lettera/index.php.

    Help?

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: No includes on higher directories?

    Quote Originally Posted by sarvar View Post
    Try this:

    include("/a/includes/header.php");
    It'll start looking in a/lettera/a/includes/header.php.

    Tested this in a localhost testing environment:

    Two files, index.php (located in htdocs/gallery1), includer.php (located in htdocs/gallery1/action).

    Inside includer.php:

    Code:
    <?php
    include ("../index.php");
    ?>
    Included index.php properly For each directory you want to go back "up" on, do ../

    So if I need to go up two directorys, "../../Filename"


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    akkudreamz's Avatar
    akkudreamz is offline x10 Sophmore akkudreamz is an unknown quantity at this point
    Join Date
    Jan 2009
    Location
    Jaipur, Rajasthan, India
    Posts
    183

    Re: No includes on higher directories?

    Livewire is right...use that method you shouldnt have problems...
    Be safety conscious. 80% of people are caused by accidents.
    My Weblog

  4. #4
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: No includes on higher directories?

    Either that, or do what I had to do when I had file heirarchy problems.

    Just specify the absolute path.

    instead of ../file.php

    just put http://www.yoursite.com/file.php

  5. #5
    akkudreamz's Avatar
    akkudreamz is offline x10 Sophmore akkudreamz is an unknown quantity at this point
    Join Date
    Jan 2009
    Location
    Jaipur, Rajasthan, India
    Posts
    183

    Re: No includes on higher directories?

    i believe you should always use relative path and not absolute one...you'll notice the reason in time
    Be safety conscious. 80% of people are caused by accidents.
    My Weblog

  6. #6
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: No includes on higher directories?

    Quote Originally Posted by akkudreamz View Post
    i believe you should always use relative path and not absolute one...you'll notice the reason in time
    QFT; whenever possible don't do absolute.

    Seriously; its a pain to migrate from Localhost to <insertdomainhere>.

    Heck, it's a pain to move from <insertdomainhere> to <insertdomainhere>/<insertsubfolderhere> :P


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  7. #7
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: No includes on higher directories?

    I like the idea of the includer, but presuambly, if you have different includes for different sections fo the site, you would also need that number of "includer.php" files...?

    What I mean is, the standard includes like header, footer etc could go in one includer, but some others like login status for example would only appear on those pages relevant to when you are logged in.

    I use DW, so migrating links is simple...... or is it?

    _____

    Edit: just thought - wouldn't you get this problem with the path to the includer?????

    Can't get my head around this....
    Last edited by freecrm; 03-23-2009 at 08:03 AM.

  8. #8
    Rolus is offline x10Hosting Member Rolus is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    9

    Re: No includes on higher directories?

    I've had problems with including on higher pads when using require and require_once (which is the same as include with only difference that a fatal error is triggered when the included page isnt found). Ever since I've used require_once(dirname(__FILE__)."/../dirname/foo.php"); making use of the __FILE__ constant. That should work always and on every server setting.

  9. #9
    digitalsoft is offline x10Hosting Member digitalsoft is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    1

    Re: No includes on higher directories?

    Quote Originally Posted by wesley09 View Post
    Need to Know:
    http://example.pcriot.com/a/includes/header.php (Would contain the header)
    http://example.pcriot.com/a/includes/footer.php (Would contain the footer)
    http://example.pcriot.com/a/index.php (The index page of directory A)
    http://example.pcriot.com/a/lettera/index.php (Another index of a higher directory)

    The Problem:
    Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text.

    Example:
    Let's say I make a page with a url of http://example.pcriot.com/a/lettera/index.php.
    And I want to include http://example.pcriot.com/a/includes/header.php and http://example.pcriot.com/a/includes/footer.php
    So, I would use the PHP include function and use those.
    The problem is, the includes won't show up, just the page of /a/lettera/index.php.

    Help?
    Hello Wesley,

    You need to appropriatley configure your php script to handle top level directories. To navigate upwards in a web server, you use /..

    So lets say, for instance. Your webserver is a ROOT level = / , you make a folder called images, so that would look like in the server - /images/

    Well, lets say you had a PHP script in a folder called scripts, and it called for one of the images in the images folder, you might be wondering. How would I go upon doing this? Well , i'ts simple, just go ../images/imagefile.jpg

    It basically tells the server to Go UP one directory, goto the images directory, and access the imagefile.jpg

    Hope this clears any misunderstanding.

+ Reply to Thread

Similar Threads

  1. Do Larger HDD's Have Higher Failure Rates?
    By Spartan Erik in forum Computers & Technology
    Replies: 6
    Last Post: 12-22-2008, 11:09 AM
  2. Password Protect Directories Thread
    By swanniebroo in forum Programming Help
    Replies: 3
    Last Post: 02-07-2008, 06:57 PM
  3. Reset to original directories and files?
    By Jambu in forum Free Hosting
    Replies: 3
    Last Post: 12-10-2007, 02:55 AM
  4. Problem with ad code (includes?)
    By Salvatos in forum Free Hosting
    Replies: 10
    Last Post: 12-12-2006, 04:16 PM
  5. Rewritten PHP Includes tutorial
    By [XiRE] in forum Tutorials
    Replies: 2
    Last Post: 07-28-2006, 10:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers