Solved

Determine file dependencies of a script?

Posted on 2008-10-14
6
252 Views
Last Modified: 2013-12-15
Hello,

Anyone know a good way to determine what the file dependencies of a particular script are? I need not just the files immediately included in the file but ALL the files that file needs to run.

So, say I've got script A, and it includes class_B.php, and class B requires_once(file_C) and file_C needs file D.

Any way to figure out, from script A, what file D is?
0
Comment
Question by:dnatal
  • 3
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
Squinky earned 300 total points
Comment Utility
You could try calling get_included_files: http://www.php.net/manual/en/function.get-included-files.php
0
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 200 total points
Comment Utility
If you have a lot of scripts which you want to track down, then you can use a registered shutdown function invoked by using the auto_prepend_file facility to use get_included_files() and store then somewhere for each script.

Watch this space...
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Something like the snippet below.

In your php.ini file you will have a line with ...

;auto_prepend_file=

If you save the snippet somewhere accessible to the web server (say Z:\LogIncludes.php) and change the ini file to be ...

auto_prepend_file=Z:/LogIncludes.php

Every script you run will have the includes logged for you.

If you run the file by itself, it should also log!


Z:\Usage>dir /s /b
Z:\Usage\58d404442823079089828b569b40f84c.log

Z:\Usage>type 58d404442823079089828b569b40f84c.log
Z:\logIncludes.php

array (
  0 => 'Z:\\logIncludes.php',
)



<?php

function logIncludes() {

	// Build string containing filename and included files.

	$s_Data = $_SERVER['PHP_SELF'] . PHP_EOL . PHP_EOL . var_export(get_included_files(), True);
 

	// Use a hash of the filename to store the data.

	// You will need to amend the path below to somewhere useful for you.

	$s_LogFile = 'Z:/Usage/' . md5($_SERVER['PHP_SELF']) . '.log';
 

	// Make sure the directory exists.

	mkdir(dirname($s_LogFile), 0777, True);
 

	// Log the file if it doesn't already exist.

	if (!file_exists($s_LogFile)) {

		file_put_contents($s_LogFile, $s_Data);

	}

}
 

register_shutdown_function('logIncludes');

Open in new window

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
I use a hash as this will reduce the complexity of the filenames in subdirectories. You COULD just save a log file next to each script, but I don't know if that is appropriate for you.


0
 
LVL 2

Author Comment

by:dnatal
Comment Utility
get_included_files() is what I was looking for. Kinda wish it was a multidimensional array so I could see the dependency structures, or even just have parent file as array key, but it'll work.

All great answers and I really appreciate all the help.
0
 
LVL 2

Author Closing Comment

by:dnatal
Comment Utility
Really appreciate the help. Split the points because they're both valid answers.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now