SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CSS & Images breaking on file inclusion

    Hello all,

    I've built this site and layout using bootstrap. http://ankursinha.net/test/ . I've broke the index file into head.php (contains the whole html head like scripts, meta, link rel, etc), then header.php (contains the logo, search bar, etc), then navbar.php (contains the navbar), and the footer. I've placed an index file along with it and I used: include 'head.php', etc and got it working. But when I created a folder forums, added the same code, but used include '../head.php', etc all the content came, but the css and the image logo didn't appear. I saw the page source for both the links are the same. Here is the link. http://ankursinha.net/test/forums/

    The codes for both are the same, just that I added two dots to traverse back to the parent directory and include files under the forums folder, the source shows everything is included but the css and images do not appear. Please help.

    Thank you

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,215
    Mentioned
    457 Post(s)
    Tagged
    8 Thread(s)
    I find the best way to link to include files is like this:

    Code:
    <?php include $_SERVER["DOCUMENT_ROOT"] . "/folder/file.php"; ?>
    Much more reliable.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did exactly like what you said, the CSS and the image show up but please look at the same page again in the forums directory, it's not the same as how it is in the parent folder (Test) that is.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,215
    Mentioned
    457 Post(s)
    Tagged
    8 Thread(s)
    In both the CSS links are now broken, so check the paths to all your files in the include files. Is the /bootstrap folder really in your root folder?

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2012
    Location
    Web
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used absolute links to include the css and the other image files and everything worked. Thanks a lot my friend. Happy New Year & Happy Coding.

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,215
    Mentioned
    457 Post(s)
    Tagged
    8 Thread(s)
    Cool. Glad I could help.


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
  •