In the <head> of my site, I'd like to use <?php include("head.php"); ?>.. is this OK?

Discussion in 'Programming' started by js09, Nov 16, 2010.

  1. #1
    For a fairly simple site, can I simply have something like this:

    
    <head>
    <?php include("head.php"); ?>
    </head>
    
    Code (markup):
    My reasoning is so that I can simple update 'head.php' and have it apply to all pages on my site.

    What are the disadvantages of this?

    Thank you!!
     
    js09, Nov 16, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That will work so long as there are no head tags in the head.php file.
    But it's better to keep the markup together, as shown in this tutorial:
    http://www.tizag.com/phpT/include.php

    Taken to the extreme, this is what your index.php file would look like:
    <?php 
    include("head.php");
    include("content.php");
    include("footer.php"); 
    ?>
    
    Code (markup):
     
    Last edited: Nov 17, 2010
    Cash Nebula, Nov 17, 2010 IP
  3. peonboy

    peonboy Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think there's no disadvantage of using this method
     
    peonboy, Nov 17, 2010 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The only disadvantage, is that any execution at runtime will add a load to the server and thus the loadtime for the webpage.

    Now, realistically speaking your going to need a hell of a lot of traffic for a single include to make a noticable difference but it is wrong to say there are no disadvantages.
     
    AstarothSolutions, Nov 19, 2010 IP
  5. longcall911

    longcall911 Peon

    Messages:
    1,672
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    0
    #5
    For a fairly simple site, you would have a fairly simple <head> block, so why use the include?

    Disadvantages. . . you can't use different stylesheets from page to page. It is an odd approach and having someone else troubleshoot the page would leave him/her scratching their head saying "why would you do that".
     
    longcall911, Nov 20, 2010 IP
  6. SterlingS

    SterlingS Greenhorn

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    13
    #6
    If your code gets too long you will lose track because of you sloppiness.
     
    SterlingS, Nov 21, 2010 IP
  7. js09

    js09 Peon

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks everyone! it's a simple site so I think it will work for now.
     
    js09, Nov 29, 2010 IP