Possible Duplicate:
When should I use require_once vs include?
For example if I have:
header part(header.php)
footer part(footer.php)
list of functions (functions.php)
list of constants (constants.php)
connect to database part(connection.php)
footer part + close the connection part(footer.php)
In these example should I use include, require or require_once and please NOTE why?
For files that contain functions, classes and other utilities, you generally want
require_onceso that nothing is accidentally redeclared in multiple libraries (or something) and breaks stuff.functions.phpconstants.phpconnection.phpFor files that are templates you usually want
require, because they should be able to be included multiple times without causing issues. (Not that that’s likely in the particular case of these two files.)header.phpfooter.phpYou never* want to use
include(orinclude_once). It’s likerequire, but only shows a warning when the file doesn’t exist – probably not what was intended.Now you noted that your footer closes the database connection. You generally want to avoid side-effects in template files. Moreover, closing the database connection is probably unnecessary. (And given that you can close it, here’s some advice: use PDO instead!)