+ Reply to Thread
Results 1 to 4 of 4

Thread: Problem Locating Header/Footer Files

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

    Problem Locating Header/Footer Files

    Hi,

    I'm running into an issue when I'm including my header.php and footer.php into my web pages. The problem is that for each web page I have to specify how far back into the directory the page needs to go to reach header and footer.

    Example: Includes for a page located in http://mysite.x10hosting.com/dev/index.php
    Where header.php and footer.php are located at http://mysite.x10hosting.com/
    PHP Code:
    <?php include('../header.php'); ?>
    /*Body*/
    <?php include('../footer.php'); ?>
    What I would like to do(and thought would work for getting back to the root directory) is this:
    PHP Code:
    <?php include('/header.php'); ?>
    /*Body*/
    <?php include('/footer.php'); ?>
    Unfortunately when I attempt to run a page using the 2nd method there I get an error saying that "/header.php could not be found in the directory /dev/index.php".

    Any help would be very much appreciated. It's such a bother to have to look and see how many directories back I need to go in order for my includes to reach the main directory and grab those damned header/footer files...

    Thank you,
    Jeeter

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Problem Locating Header/Footer Files

    you can use chdir('/path/you/want/')

    you have to use the full path, ie /home/user/public_html
    Last edited by garrettroyce; 05-07-2009 at 02:40 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Problem Locating Header/Footer Files

    You could use virtual() to include the files. You could also add the document root to the include_path, allowing you to use "include('header.php')". Slightly better would be to create a directory named (eg) "include" in public_html (or wherever) and put the path to "include" in the include_path. That way you can separate pages from the files your site uses internally.

  4. #4
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: Problem Locating Header/Footer Files

    I simply do a
    PHP Code:
    define('ROOT''../'); 
    and include files doing
    PHP Code:
    <?php include(ROOT 'header.php'); ?>
    /*Body*/
    <?php include(ROOT 'footer.php'); ?>
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. Cannot copy files using WebDisk
    By truffle in forum Free Hosting
    Replies: 2
    Last Post: 11-02-2008, 09:36 PM
  2. Introduction to Linux CLI
    By HomerJ in forum Tutorials
    Replies: 3
    Last Post: 02-26-2008, 08:53 AM
  3. Windows Sortcuts
    By Blazer9131 in forum Computers & Technology
    Replies: 3
    Last Post: 11-29-2007, 04:07 PM
  4. FTP and Files Problem...
    By DizzyTechnology in forum Free Hosting
    Replies: 13
    Last Post: 09-10-2006, 07:52 PM
  5. Ftp Timeout problem
    By ironcross77 in forum Free Hosting
    Replies: 7
    Last Post: 04-12-2005, 08:53 PM

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