What should my index.php include?

Discussion in 'PHP' started by woggy, May 21, 2006.

  1. #1
    I'm setting up a new layout to a webpage and I'm very new to this..

    So I have a question to how I should set up the code in my index-file.

    Should it only include pointers to f.x. "header.php" where the top-picture and topmenu should be, "content.php" to where the text should be and "bottom.php" to where the - well - bottom should be?

    And within these code what actually is to be coded?
    Is THAT the smartest way to do it, is it really possible to do it that way?

    If it ain't the smartest way, what is it then?

    If this is the way to do it, can somebody please show a php-code of an actual index.php ? I think it's a good way to learn, to just look at the code.
     
    woggy, May 21, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The index page should be set up the same as any other page on your site.

    If you want to use a common header and footer thats fine.

    <?php
    include("header.php");
    ?>
    content here
    <?php
    include("footer.php");
    ?>
    PHP:
     
    mad4, May 22, 2006 IP
  3. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    I would highly recommend including a header/menu/footer file. Otherwise, what happens when you need to change something in one of these? You'll have to change it everywhere! I wouldn't recommend using includes for content -- you would be making a bigger mess that way. I also use includes for ads.

    I would also get in the habbit of using include_once instead of include. The same goes for require.
     
    wmburg, May 22, 2006 IP
  4. Veselin Stoilov

    Veselin Stoilov Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes, you can use include for any page section that you repleat on your web site. For example, I have a news scroller on my web site which is in external php file, and when I want to put that scroller I just use the include(). This way, if I change the scroller it updates on every page.
     
    Veselin Stoilov, May 24, 2006 IP
  5. Luke

    Luke Peon

    Messages:
    111
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Another very common way is to use a main index, and include the pages in the part where the content belongs, and have something like /?page=news to access the middle content.

    INDEX page
    INDEX page
    INDEX page
    include($page.'.php'): <- If you use this, put some error checking on to prevent users manipulating it.
    INDEX page
    INDEX page
    INDEX page
     
    Luke, May 24, 2006 IP
  6. sebastya

    sebastya Well-Known Member

    Messages:
    2,449
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    138
    #6
    how do u put error checkin on it?
     
    sebastya, May 27, 2006 IP
  7. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Checking for what kind of errors?
     
    wmburg, May 28, 2006 IP
  8. Veselin Stoilov

    Veselin Stoilov Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    probably asking for

    if (!include($page.'.php')) die("file not included");
     
    Veselin Stoilov, Jun 6, 2006 IP
  9. t2000q

    t2000q Prominent Member

    Messages:
    4,636
    Likes Received:
    192
    Best Answers:
    0
    Trophy Points:
    300
    Digital Goods:
    1
    #9
    what do you mean "users manipulating it" - you mean your site getting hacked, and if so if this type of coding vunerable?
     
    t2000q, Jun 7, 2006 IP
  10. sebastya

    sebastya Well-Known Member

    Messages:
    2,449
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    138
    #10
    yeh ^^ they can load anything onto your site thru that code...I found out the hard way
     
    sebastya, Jun 8, 2006 IP
  11. Deliwasista

    Deliwasista Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #11
    Deliwasista, Jun 11, 2006 IP