Page 1 of 1

using include_once for headers, footers etc?

Posted: Mon Oct 18, 2004 6:30 pm
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.

Posted: Mon Oct 18, 2004 6:38 pm
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.

Posted: Mon Oct 18, 2004 6:43 pm
by bradles
Thanks kettle_drum.