[SOLVED] using include_once for headers, footers etc?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

using include_once for headers, footers etc?

Post by bradles »

I have an index page that has header/navigation/contents/footer. The header, navigation and footer are just straight includes like:
<?php include 'navigation.php';?>

The contents is dynamically generated from links the user chooses from the navigation and passed to the index page as page=home or page=contact etc. The script puts the name together in a variable and then passes it to the page so it is like:
<? include "$page" . ".php";?>

My question is, should I use include_once rather than include for the header, navigation and footer as these files are not changing? Does it make much difference to server overhead? Or am I barking up the wrong tree with this?

Brad.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

It just ensures that you dont include the same file twice and is really used to make sure you dont insert the same external file of classes/functions twice and get errors that you have already declaired those classes/functions before.

In the case of adding headers and footers it doesnt really need to check if the file has been included before or not - as it wont have been (or you will have 2 headers etc).

Since require_once() or include_once() have to check to see if the file has already been included before they are bound to take slightly longer to execute - but its still not really noticable.
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post by bradles »

Thanks kettle_drum.
Post Reply