I was wondering if it's possible to detect programmatically whether a script has been included/required inside another script or whether it is executing standalone.
For example, if I have a script called process_data.php, can I add code to process_data.php that will tell me whether I called it directly:
http://host/process_data.php
/usr/local/bin/php -q process_data.php
or whether I called it from another file:
include('process_data.php');
require('process_data.php');
Basically, I'm trying to write some functions into process_data.php that can be imported into other code but, if the file is called directly, I want a different set of functions (a main() block to borrow from C) to execute instead.
I know I can do this by checking for the existance of a variable (say $script_included = TRUE ) but this requires setting the variable in all the code that is using this file. I'd rather find a way for the process_data.php script to do it autonomously.
Thanks