How can the global variable $_SCRIPT_NAME be used in PHP to retrieve the currently executed file?

To retrieve the currently executed file in PHP, you can use the global variable $_SERVER['SCRIPT_NAME']. This variable contains the path of the currently executing script. By accessing this variable, you can get the name of the file that is being executed. You can use this information for logging, debugging, or any other purpose in your PHP script.

$currentFile = $_SERVER['SCRIPT_NAME'];
echo "Currently executed file: " . $currentFile;