Se desiderate creare uno script che debba essere eseguito solo in background e l’accesso diretto al file deve essere bloccato, seguite questo semplicissimo metodo per fare quanto detto!

 
< ?php
//if the current file the user is browsing for is the file block.php then block the access
if(basename($_SERVER[‘SCRIPT_FILENAME’]) == "block.php"):
echo "Sorry but you cannot browse this file directly!";
exit;//this will make sure the browser stops here and won’t go any further
endif;
?>
 
If you are browsing this file directly you will not see this text, but if you are including
this file in another file using the include(); function you should see this text.
 

fonte: www.sastgroup.com