Get filename of file which ran PHP include

后端 未结 7 2155
后悔当初
后悔当初 2020-11-28 11:47

When using the PHP include, how can I find out which file is calling the include? In short, what is the parent\'s file filename?

7条回答
  •  清酒与你
    2020-11-28 12:38

    In the parent file, add this line before including the child file:

    $_SESSION['parent_file'] = $_SERVER['PHP_SELF'];
    

    And then in the child file, read the session variable:

    $parent_file = $_SESSION['parent_file']
    

提交回复
热议问题