In regards to
__FILE__ != $_SERVER['SCRIPT_FILENAME'] to check for a file as an include:
This only works if you are using PHP as an Apache module; when using PHP as a CGI binary on shared hosts, the filepaths may differ, even if they end up pointing to the exact same file.
For example, __FILE__ might be /home/SERVER/USER/SITE/test.php
and $_SERVER['SCRIPT_FILENAME'] might be /home/USER/SITE/test.php
Because of the SERVER included in the __FILE__ path, the comparison returns true, even though the file is not being included by any other file.