Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29

    Using php include statement to re-use code

    Hi

    Every time I make a change to my standard page header, footer etc, I had to repeat it once per screen. Which was proving very labour intensive.

    I have now utilised the PHP include command to include standard headers and footers in all my pages so that I only have to make the change once.

    Because of the php code now in my home page I have to call it index.php. It seems to work OK when I tested it.

    Is this the correct way to reuse code in PHP and will there be any problems calling my home page index.php?

    Any feedback on this would be appreciated.

    Cheers
    Andy

  2. #2
    Join Date
    Sep 2001
    Location
    Pune, Maharashtra, India.
    Posts
    24
    I don't see anything wrong with it. If you've just used the include statements it should be fine. May be you can show us your code and we can help better then?

  3. #3
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    Hi

    My code is simply:

    <html>
    <?
    include ("header.php");
    ?>

    All the main code for page is included here

    <?
    include ("footer.php");
    ?>

    </html>

  4. #4
    Join Date
    May 2002
    Location
    Modesto, CA
    Posts
    3,414
    Originally posted by AC1
    Hi

    My code is simply:

    <html>
    <?PHP include ("header.php"); ?>

    All the main code for page is included here

    <?PHP include ("footer.php"); ?>

    </html>
    dotGig
    <:<: [Fruit eating linux administrator]

  5. #5
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    I used to do it like that but now I tend to use classes... as I use a number of global functions across the sites.

    BTW you don't have to include PHP in <?PHP

    Especially if you have short_tags enabled (which is by default).

  6. #6
    <?PHP include ("header.php"); ?>

    the PHP after the ? is not needed. Although it is recommended and good practise to always use it.

    BTW, what you are trying to do it using templates. It will work the way listed.
    YourCheapHost.com - Low cost multi domain hosting solutions. [Legal adult content friendly]
    Reliable web site hosting is our motto. We have Alertra stats to back that up.
    Proven provider of high quality shared and reseller accounts since 2002.

  7. #7
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    Hi

    Thanks for all the comments, I just wanted to make sure I was not going down the wrong path with this.

    Cheers
    Andy

  8. #8
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Yes I only use classes as I tend to use a lot of XML and XSLT and it makes it easier for the XML caching

  9. #9
    Join Date
    Sep 2001
    Location
    Pune, Maharashtra, India.
    Posts
    24
    Why not put the HTML start and end tags in the header and footer files as well?

  10. #10
    Join Date
    Aug 2002
    Location
    Baltimore, Maryland
    Posts
    580
    you dont do this already? the include statement is the lazy programers friend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •