The functions which will help you on your way are [MAN]include[/MAN] and [MAN]require[/MAN]. They both have the same effect, but if a require()'d file does not exist PHP will generate a fatal error and stop. With include() PHP generates a warning and carries on processing the rest of the script. To illustrate with a basic script:
<?php
require( '/path/to/templates/siteheader.php' );
if( file_exists( "/path/to/templates/$_GET['page'].php" ))
{
require( "/path/to/templates/$_GET['page'].php" );
}
else
{
require( "/path/to/templates/homepage.php" );
}
require( '/path/to/templates/sitefooter.php ');
?>
You would call this script with a URL of myscript.php?page=pagename. The script include a file /path/to/templates/, then will check if a file exists at /path/to/templates/pagename.php, and require it if it does. If not it will fall back to homepage.php. Then finally require sitefooter.php.