Page 1 of 1

find out which files are called

Posted: Mon Feb 27, 2012 8:51 pm
by yellowrabbit
Hello

I have a php website. I am trying to trace (find out) which files are called when a page is displayed.

For example on certain pages that get displayed it may call up to 6-7 files. I would like to know the name of the files and the order they are called.

As through out the code there is a lot of

include_once("global/global.libs.php");

Is there any may to easily trace this without having to go through page by page on the code and try to figure out what is happening.

Essentially I just want the file name eg global/global.libs.php logged somewhere

Thanks in advance

Re: find out which files are called

Posted: Mon Feb 27, 2012 8:56 pm
by Celauran

Re: find out which files are called

Posted: Tue Feb 28, 2012 2:30 am
by temidayo

Re: find out which files are called

Posted: Wed Feb 29, 2012 9:24 pm
by puma10
Thanks for the response guys. This looks pretty promising but unfortunately I am still learning so my programming knowledge is lacking a little bit here to get the job done.

Code: Select all

<?php
 // Filename is index.php
 include('test_include.php');
?>
<?php 
 function get_current_files_path($file_name) 
 { 
   //find the current files directory 
   $includes = get_included_files(); 
   $path = ""; 
   for ($i=0; $i < count($includes); $i++) 
   { 
     $path = strstr($includes[$i], $file_name); 
     if ($path != false) 
     { 
       $key = $i; 
       break; 
     } 
   } 
   $path = str_replace(getcwd(), "", $includes[$key]); 
   $path = str_replace("\\", "/", $path); 
   $path = str_replace($file_name, "", $path); 
   $path = ltrim($path, "/"); 
   
   echo $path; 
 } 
?>
<?php 
get_current_files_path('index.php');
?>
Am I suppose to pass index.php to the function or the actual include path. The above is producing no result at all actually. I'm sure there are many errors in my above code, like I said it's a learning processes. Thanks all for being digital teachers ha!