
09-20-2002, 05:35 AM
|
|
Newbie
|
|
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
|

09-20-2002, 06:37 AM
|
|
Newbie
|
|
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?
|

09-20-2002, 07:26 AM
|
|
Newbie
|
|
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>
|

09-20-2002, 07:35 AM
|
|
Web Hosting Master
|
|
Join Date: May 2002
Location: Modesto, CA
Posts: 3,414
|
|
Quote:
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]
|

09-20-2002, 08:20 AM
|
|
Web Hosting Master
|
|
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).
|

09-20-2002, 09:04 AM
|
|
Web Hosting Master
|
|
Join Date: Aug 2002
Posts: 2,520
|
|
<?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. 
__________________
Net-Trend.com - Full featured multi domain hosting solutions.
RevoServe.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.
|

09-20-2002, 09:09 AM
|
|
Newbie
|
|
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
|

09-20-2002, 09:49 AM
|
|
Web Hosting Master
|
|
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
|

09-20-2002, 02:45 PM
|
|
Newbie
|
|
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?
|

09-20-2002, 09:01 PM
|
|
Web Hosting Master
|
|
Join Date: Aug 2002
Location: Baltimore, Maryland
Posts: 580
|
|
you dont do this already? the include statement is the lazy programers friend 
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|