Can an included PHP file know where it was included from?

后端 未结 6 1729
遇见更好的自我
遇见更好的自我 2020-12-10 11:31

For example,

This is index.php


Can header.php know it was included by index.php?

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 12:00

    Easiest way in the web server environment: $_SERVER['SCRIPT_FILENAME'] will show the original file that is called.

    Universal way - debug_backtrace() will show you all previous steps of the execution, which will include calls to require/include functions.

提交回复
热议问题