The part you were supposed to read is:
You can use the following in files that you want to include, but not run directly. The script will exit if it's run as the top-level script, but will not exit if it's included from another script. Of course this won't work in the command line mode.
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
exit;
}
I might enhance that by using header() to send a 404 before the exit.