Help with "includes"

Discussion in 'PHP' started by fxstadium.com, May 12, 2008.

  1. #1
    Hi guys, hope one of you can help we with this problem.
    So here's the situation.

    So I've made an header.php file that would be included in all of my other pages.
    This header.php contains the navigation, logo as well as the <head> <title> and the css link>
    This file is currently sitting in

    mainfolder/includes/header.php

    I've included this file on all of my pages that are located in the mainfolder, and it works just fine.

    Here's the problem. I started creating pages that is placed in
    mainfolder/subfolder/page.php
    The problem with this is that since, i'm using the same header.php file. The css links would not load for this page. the css file is located at
    mainfolder/stylesheets/main.css
    <link rel="stylesheet" type="text/css" href="stylesheets/compare.css" />

    if i change the link tag to
    <link rel="stylesheet" type="text/css" href="../stylesheets/compare.css" />
    It would work for that page, but in turn, the pages at the mainfolder would no t load.

    Can someone advice me how to get around this. I hope i've explained it well enough.
    Thanks
     
    fxstadium.com, May 12, 2008 IP
  2. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm sure there are cleaner ways than this, but I've always found this to be the least headache inducing.

    So, in your header, declare
    $site = "http://www.mysite.com/";
    Code (markup):
    Then your css file would look like
    <link rel="stylesheet" type="text/css" href="<?php echo($site); ?>mainfolder/stylesheets/compare.css" />
    Code (markup):
     
    Altari, May 12, 2008 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    if your script is hard coded then that would be the difficult part.
    one is to Altari's suggestion..

    are you using a page switch?
    i mean,

    switch($selPage)
    {
    case 1:
    echo akldaj;da';
    break;
    }
    or a link to other page?
     
    bartolay13, May 12, 2008 IP