SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    arizona
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy php question.... I think!!

    Hi all,

    I'm trying to call my websites header which resides in the root directory to other files in other folders.

    Root directory
    - header.php

    root/folder/needsheader.php

    I cant succesfully get my needsheader.php file to display the header that resides in the root directory. Is there anyway to do it other than using the absolute file name.

    Code:
    include "http://www.website.com/folder/header.php";
    Is there a better way than my example?

    Thanks, Norris

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    The problem is that you're including a webpage, being requested as such.
    You need to include the file directly:

    PHP Code:
    include "folder/header.php";
    // or, if you're working in - say - 'folder2' (which resides next to 'folder'):
    include "../folder/header.php" 
    Or you could use the absolute path to the file:

    PHP Code:
    include "/var/www/folder/header.php"
    Note that this last version will be problematic if you ever change the folder layout of your website or move to a different host, as you may have to change all your include statements.

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can also use a combination of dirname() and __FILE__ (or __DIR__ depending on your php version) to create an absolute path based on the current file if you prefer that

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    arizona
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm. none of those are working. I did make a mistake about where I was trying to put the file.

    I'm trying to grab file header.php and add it into root/folder/folder/file.php

    How do I grab something from the root folder. Right now my include statement is

    Code:
    include "header.php";
    Its not pulling the header from the root folder.

    Thanks for all your help.

  5. #5
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Try adding a / before header.php or
    PHP Code:
    include($_SERVER['DOCUMENT_ROOT']."/header.php"); 
    Ryan B | My Blog | Twitter

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    arizona
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Rguy. I've been racking my brain over how to do this simple thing. Now I only have edit 160 pages with that code for the footer and header. Thanks. i might get to see sun light today.

  7. #7
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You are welcome
    Ryan B | My Blog | Twitter

  8. #8
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by norrisboat View Post
    Thanks Rguy. I've been racking my brain over how to do this simple thing. Now I only have edit 160 pages with that code for the footer and header. Thanks. i might get to see sun light today.
    Do you have a good search and replace in your IDE or if you use Linux you
    Code:
    find . -name '*.html' | xargs perl -pi -e 's/oldtext/newtext/g'.
    BTW no talking about Sun today... unfair, we have blowing snow, drab skies, and very cold - no Sun here
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •