Is is possible for a php script to know if another script calls it via require or require_once?
eg:
if scripta.php calls me do xyz;
if scriptb.php calls me do abc;
Edit: Thanks for your suggestions guys. It was more of a what if question, rather than an actual problem. I realise I could set a variable, $caller and update it when I made the require statement. I just wondered if there was another way to do this in the file that’s being called 🙂
If you just want to check if the your file was included or not:
$_SERVER['SCRIPT_FILENAME']will always return the filename of the script that has been originally called. (e.g. “start.php”)The constant
__FILE__will always return the true file name of the script that it is used in. (e.g. “library.inc.php”)So you can do something like this:
If you want to distinguish from where the file has been included: