Not sure if this is the correct way of doing things (as I’m still “learning” PHP), but it worked for me.
Basically I wanted to include a php file, but not allow the user to be able to directly go to that same file.
Example: index.php calls upload.php. Blocking the end user from going straight to upload.php (or even viewing the contents) would have been a bad idea.
This is running on a debian server with LAMP.
nano index.php
$including = true;
nano upload.php
if (!$including) exit(“Direct access is not permitted.”);
That’s it. Now navigate to upload.php and you’ll see it doesn’t allow it to work. Navigate to index.php and you’ll see the call still works. Great? Probably not, but it still works. Hopefully it doesn’t introduce any other bugs – but it’s a purely testing system anyway. So hack away.