1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

simple include question

Discussion in 'PHP' started by oo7ml, Aug 3, 2007.

  1. #1
    My site consists of over 30 pages, and each page has the same footer (ending)

    I was thinking of adding an include
    <?php include("footer.php");?>
    PHP:

    Does it matter what code is in the footer.php e.g

    say it includes the closing </table> </body> and </html> tags

    <tr>
    <td>
    <p> this is the footer </p
    </td>
    </tr>
    </table>
    </body
    </html>
    HTML:
    but it doesn't have the opening <html> <body> <table> tags

    Is this bad coding practice because i don't have the opening tags in it as well or does it matter?
    SEMrush
    PLEASE EVERYONE ANSWER AS I THINK THIS COULD BE VERY OPINIONATED
     
    oo7ml, Aug 3, 2007 IP
    SEMrush
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It doesn't matter as such, but I would say it's bad practice, though quite common.

    It does limit re-use because it means your include then places a requirement on anything that includes it.

    It would be safer to have pages that always started with <html> and ended with </html> for example, and possibly the main table layout, and then includes which went in particular cells or whatever.

    If you were to build another site, you wouldn't be able to use any of your includes unless the rest of the site had the exact same structure.
     
    ecentricNick, Aug 3, 2007 IP
  3. The Webmaster

    The Webmaster IdeasOfOne

    Messages:
    9,518
    Likes Received:
    717
    Best Answers:
    0
    Trophy Points:
    360
    #3
    No it is not a bad coding practice. Browser will render the final HTML page as whole.

    PHP is preprocessor so it processes the code before sending output to the client machine, thus include part will be processed before the web server omits output. So it will be shown as one single complete html page..
     
    The Webmaster, Aug 3, 2007 IP
  4. daman371

    daman371 Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Correct. PHP is processed and all of the HTML is output. It would only be bad if footer.php was the entire page and nothing else was outputted before it.
     
    daman371, Aug 11, 2007 IP
  5. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There is a difference between "bad" and "bad practice". The fact that it works doesn't make it right. My point was that it limits you - it ties you into one given structure and that limits your scope to re-use it again in the future on another project.

    That's fine if you don't mind re-inventing the wheel every time you start something new. But with a little forethought, your includes can be designed in a generic fashion where they can easily be plugged into any other project.
     
    ecentricNick, Aug 13, 2007 IP
  6. daman371

    daman371 Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thus this is why there are theming systems such as Smarty.
     
    daman371, Aug 15, 2007 IP
  7. dirvish

    dirvish Peon

    Messages:
    142
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If it is bad practice then I'm guilty...
     
    dirvish, Aug 16, 2007 IP