Check if a file was included or loaded

后端 未结 12 1217
轻奢々
轻奢々 2020-12-08 13:35

Is there any elegant way to check if a file was included by using include/include_once/require/require_once or if the pag

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 13:59

    It's sooo simple.. I have made something like this:

    //code for file.php
    if (!isset($file_included)){
       echo "It was loaded!";
    } else {
      echo "It was included!";
    }
    
    //code for loader.php
    //proves that atleast loader.php has loaded,
    //not the file we targeted first..
    $file_included = true;
    include("../file.php");
    

    And that's it.. as simple as in python.

提交回复
热议问题