$_SERVER['PHP_SELF'] tells what is the main page
Even in one included page will tell same PHP_SELF,
as the main script page which did the include.
There are many ways to test if an included page was really included
or called directly, and so make an exit() to stop in such case.
Using value of $_SERVER['PHP_SELF'] is one such test.
<?php
echo $_SERVER['PHP_SELF']; // the main script page
echo '<br>';
echo __FILE__; // this file's path
echo '<br>';
echo basename(__FILE__); // this file's name
echo '<br>';
echo '<br>';
// test if this file's name is a part of PHP_SELF
// which means this file was NOT included, but called directly
// if so, exit() to end script
if(stripos($_SERVER['PHP_SELF'], basename(__FILE__))!==FALSE) exit('stop!');
?>
This is how you can use it.
Put as first line in all your include files, to protect them:
<?php
// test for hackers and stop with exit()
if(stripos($_SERVER['PHP_SELF'], basename(__FILE__)) !== FALSE) exit('stop!');
// rest of code
// more here
?>