You can do any of these things, in order of desirability (from "good" to "it kind of works"):
- Create them outside your web root. Example, assuming that
/somepath/example.com/htdocs/ maps to http://example.com/:
/somepath/example.com/htdocs/index.php
/somepath/example.com/includes/header.php
/somepath/example.com/includes/footer.php
index.php:
<?php require_once('../includes/header.php') ?>
- Prevent access via .htaccess
<Files (header|footer).php>
Deny from all
</Files>
- (a hack if everything else fails) set a constant in the main file, die silently if not found.
index.php:
<?php define('INCLUDED_FROM_MAIN_FILE_EXAMPLE_COM',true) ?>
header.php:
<?php if (!defined('INCLUDED_FROM_MAIN_FILE_EXAMPLE_COM')) { die(); }