Check if a file was included or loaded

后端 未结 12 1219
轻奢々
轻奢々 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 13:50

    Working solution:

    $target_file = '/home/path/folder/file.php'; // or use __FILE__
    
    if ($x=function($e){return str_replace(array('\\'), '/', $e);}) if(in_array( $x($target_file), array_map( $x ,  get_included_files() ) ) )
    {
        exit("Hello, already included !");
    }
    

提交回复
热议问题