Get name of file that is including a PHP script

后端 未结 6 2017
遇见更好的自我
遇见更好的自我 2020-12-16 11:22

Here is an example of what I am trying to do:

index.php

list.php

6条回答
  •  悲哀的现实
    2020-12-16 11:59

    In case someone got here from search engine, the accepted answer will work only if the script is in server root directory, as PHP_SELF is filename with path relative to the server root. So the universal solution is

    basename($_SERVER['PHP_SELF'])
    

    Also keep in mind, that this returns the top script, for example if you have a script and include a file, and then in included file include another file and try this, you will get the name of the first script, not the second.

提交回复
热议问题