header and footer

Discussion in 'PHP' started by fgsg, Apr 21, 2010.

  1. #1
    Hi, i use simple option:

    <?php include('header.php'); ?>
    
    Code (markup):
    and

    <?php include('footer.php'); ?>
    
    Code (markup):
    but when i put this code in my files in other folder /live dont show me header and footer any know why ?
     
    fgsg, Apr 21, 2010 IP
  2. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    <?php include('/live/header.php'); ?>
    Code (markup):
    You have to use the folder path '/live/footer.php' to point to the file correctly.

    Also if you need to go up a directory use '../' in front of you file.
     
    Imozeb, Apr 21, 2010 IP
  3. fgsg

    fgsg Well-Known Member

    Messages:
    275
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3

    yup but then dont work css ? maybe because i have ./styles.css maybe i need put page.com/styles.css or ?
     
    fgsg, Apr 21, 2010 IP
  4. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For linking your CSS use the full url. http://www.yoursite/yourfolder/yourfile.css

    Inside the CSS use # signs before each element like for

    <div id="main"><div id="header"></div></div>
    HTML:
    Use this in CSS:

    #main{
    background-color:#FFFFFF;
    }
    #main #header{
    background-color:#FFFFFF;
    }
    Code (markup):
     
    Imozeb, Apr 22, 2010 IP
  5. fgsg

    fgsg Well-Known Member

    Messages:
    275
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    thx bro and what with images full url or ? and with links url example ./live.php or http://www.page.com/live.php ?
     
    fgsg, Apr 22, 2010 IP
  6. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #6
    I would setup a load of constants which define all your includes/front-end paths something like this:

    File called config.inc.php:

    define("__SITE_URL", "http://www.mysite.com");
    define("__IMAGE_URL", __SITE_URL."/images");
    define("__CSS_URL", __SITE_URL."/css");
    
    define("__ROOT_PATH", "/home/site/public_html");
    
    PHP:
    Then as long as you include("config.inc.php") before doing anything within your code, you can easily set paths on your files.

    include(__ROOT_PATH.'/live/header.php');
    PHP:
    <link rel="stylesheet" type="text/css" href="<?php echo __CSS_URL; ?>/styles.css">
    HTML:
    <img src="<?php echo __IMAGE_URL; ?>/myimage.jpg">
    HTML:
    That way if you move things about you've only got the config to update. It also means all your paths are now absolute which generally makes things easier.
     
    mfscripts, Apr 22, 2010 IP
  7. devidhood

    devidhood Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hiiiiiiiii

    According to me header and footer is used to maintain a perticular template in every page on site for that we make 2 pages header.php and footer.php here we can design template.so for that we have include that file in particular page for that we used include function

    syntax is: inculde("filename");
    before file name we can define path of file

    i hope this will help u

    thanks

    Regards

    Devid
     
    devidhood, Apr 22, 2010 IP
  8. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yup. For images use the full url. It makes your script easier to change if you need to move folders.
     
    Imozeb, Apr 22, 2010 IP
  9. HighRankingSEO

    HighRankingSEO Well-Known Member

    Messages:
    423
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    125
    #9
    Config.inc.php tip was pretty nice,,,thanks
     
    HighRankingSEO, Apr 22, 2010 IP
  10. fgsg

    fgsg Well-Known Member

    Messages:
    275
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #10
    thx for all :)
     
    fgsg, Apr 23, 2010 IP