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.
[SOLVED] using include_once for headers, footers etc?
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
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.
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.