This function gives you a list of all the included files (via include() or require()) at the time of calling. These are listed in the order they were included.

The first element of the array will always be the “main” file. It is treated as an included file. If a file is included more than once, it is only listed once in the array - in its original position in the array.

<?php
// This is test2.php
include 'test.inc';
<?php
// List contains even what an included file includes
// This is test.php
include 'index.html';
include 'test2.php';
$list = get_included_files();
var_export( $list );
/*
array (
  0 => '/var/www/test.php',
  1 => '/var/www/index.html',
  2 => '/var/www/test2.php',
  3 => '/var/www/test.inc',
)
*/
<?php
// index.html is not added to the list twice
// This is test.php
include 'index.html';
include 'test2.php';
include 'index.html';
$list = get_included_files();
var_export( $list );
/*
array (
  0 => '/var/www/test.php',
  1 => '/var/www/index.html',
  2 => '/var/www/test2.php',
  3 => '/var/www/test.inc',
)
*/
<?php
// List is based on the includes at time of calling the function
// This is test.php
include 'index.html';
$list = get_included_files();
include 'test2.php';
 
var_export( $list );
/*
array (
  0 => '/var/www/test.php',
  1 => '/var/www/index.html',
)
*/
<?php
// file_get_contents() for example, does not add to the list
// This is test.php
include 'index.html';
file_get_contents( 'test2.php' );
$list = get_included_files();
var_export( $list );
/*
array (
  0 => '/var/www/test.php',
  1 => '/var/www/index.html',
)
*/