Reputation: 1061
I'm looking for a way to get what the current script running. But the thing is I can't use __FILE__
since it gives me the file i'm currently in and in the case of an included file, I want the initial file.
So if I run
index.php
and in that file there is an include('test.php')
I want to be able in test.php to get 'index.php'
as the current file im runing.
I know I could do __FILE__
in index.php
and keep the value in an variable. But i'm looking for a way with minimal change to my files.
Also the script is running in CLI on windows. So trying to parse the the path wont work also.
What are my options?
Thanks to everyone taking the time to read this :)
Upvotes: 3
Views: 1691
Reputation: 11689
You have to use $_SERVER[PHP_SELF]
.
According to documentation:
The filename of the currently executing script, relative to the document root.
$_SERVER[PHP_SELF]
works also on CLI interface. (Edit: ... but I doesn't have tested in Windows)
Upvotes: 6