I have a file named startpage.inc.php
and I want to include it but prevent, that anybody can open it in his Browser. Is it possible?
Possible:
<?php
include 'inc/startpage.inc.php';
?>
To prevent:
www.example.org/inc/startpage.inc.php
You have several options.
Check whether a constant is defined within your file. If not, exit;
. Define a constant in the file that includes your startpage.inc.php
. This is how a lot of free scripts prevented unwanted inclusions.
Don't have the script in the publicly available folder. Move it below document root so it can never be accessed directly, only when included via include
or require
.