What are some ways to determine if a PHP script is executed directly by a user or included in another script?

When a PHP script is executed directly by a user, it typically has access to the $_SERVER['SCRIPT_FILENAME'] variable, which contains the full path of the script. On the other hand, when a PHP script is included in another script, the $_SERVER['SCRIPT_FILENAME'] variable will not be set. Therefore, checking the existence of this variable can help determine if a script is executed directly or included in another script.

if(isset($_SERVER['SCRIPT_FILENAME'])) {
    // Script is executed directly
    echo "Script is executed directly by a user.";
} else {
    // Script is included in another script
    echo "Script is included in another script.";
}