Using Include in Web Page design

Discussion in 'PHP' started by Kiran Prakash, Nov 12, 2010.

  1. #1
    I am new to designing web pages using PHP so request the experts to advise me.

    In order to keep the index page simple I have used the "include" function for isolating all the info on my website.

    Please advise whether this is a good practice or not ?
     
    Kiran Prakash, Nov 12, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    bencummins, Nov 12, 2010 IP
  3. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello,

    I would advise you splitting up the Header and Footer file then just include it for simplicity. Then just: include("header.php"); and include("footer.php");. In my opinion that is the easiest way to do it. That is how i always do it.
     
    CPAPubMichael, Nov 12, 2010 IP
  4. dixcoder

    dixcoder Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #4
    if you are sure with your header part that will be common for all the pages then better split the design into header and footer
     
    dixcoder, Nov 12, 2010 IP
  5. directhost

    directhost Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You definitely want to make use of include files whenever possible, even for simple things. They really do help when you have to make changes. I use different includes to separate the content on the page and then sprinkle in some functions that help place widgets or other smaller parts of my page.


    Here's a little tip that might help you if you didn't already know:

    The other (better) option is setting the PHP directory path on your webserver so it gets included automatically.
     
    directhost, Nov 12, 2010 IP
  6. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #6
    When it comes to include(), require() and code reuse in general the think to keep in mind is Don't Repeat Yourself or DRY. So keep it DRY. Never copy and past anything! if it can be put in a common included file. You'll save yourself sooo much time in the long run and future programmers who work on your site will thank you.
     
    superdav42, Nov 12, 2010 IP