hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Using php include statement to re-use code
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Using php include statement to re-use code

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-20-2002, 05:35 AM
AC1 AC1 is offline
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

Reply With Quote


Sponsored Links
  #2  
Old 09-20-2002, 06:37 AM
Myth_Pharoah Myth_Pharoah is offline
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?

Reply With Quote
  #3  
Old 09-20-2002, 07:26 AM
AC1 AC1 is offline
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>

Reply With Quote
Sponsored Links
  #4  
Old 09-20-2002, 07:35 AM
Samuel Samuel is offline
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]

Reply With Quote
  #5  
Old 09-20-2002, 08:20 AM
Rich2k Rich2k is offline
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).

Reply With Quote
  #6  
Old 09-20-2002, 09:04 AM
net-trend net-trend is offline
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.


Reply With Quote
  #7  
Old 09-20-2002, 09:09 AM
AC1 AC1 is offline
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

Reply With Quote
  #8  
Old 09-20-2002, 09:49 AM
Rich2k Rich2k is offline
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

Reply With Quote
  #9  
Old 09-20-2002, 02:45 PM
Myth_Pharoah Myth_Pharoah is offline
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?

Reply With Quote
  #10  
Old 09-20-2002, 09:01 PM
dreamrae.com dreamrae.com is offline
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

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Students Contribute to Joomla through Google Summer of Code Program Web Hosting News 2012-05-08 15:22:35
Web Host Go Daddy Sees Record Mobile Traffic on Super Bowl Sunday Web Hosting News 2012-02-06 10:53:00
Linux Foundation Website Down After Security Breach Last Week Web Hosting News 2011-09-12 20:32:11
Non-Profit New Zealand Computer Society to Develop Cloud Code of Practice Web Hosting News 2011-09-02 17:22:36
SSL Provider GlobalSign Launches Spanish Website Web Hosting News 2011-08-12 14:01:12


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?