Solved

A PHP file is being included from somewhere other than my application folder. How can I find it?

Posted on 2014-02-12
6
459 Views
Last Modified: 2014-02-13
I'm trying to maintain a legacy application which has a real mess of calls like
include_once("config.php");

Open in new window

The trouble is that a config.php file is being loaded from somewhere outside of my application folder, and returning an error, and exiting. This will be because PHP has a path setting allowing it to pick up files from somewhere else if they aren't found locally.

Is there a log of which files are being loaded when my application is running, or some other way of tracking down the location of that file?

Thanks
0
Comment
Question by:Terry Woods
6 Comments
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 50 total points
ID: 39855319
There is a very nice little tool here:

http://12g.com/ghosts/replace.htm

which will search an entire folder and subfolders for any given string.  Just use it on your high-level folder of the code, searching for "include" and for "require", or if you are sure of the name, search for "config.php".
0
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 133 total points
ID: 39855338
Notepad++ has the same ability, and supports regular expressions.
So does WinGrep...

@TerryAtOpus: What does the  "include_path" say?

HTH,
Dan
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 134 total points
ID: 39855413
'phpinfo()' will tell you what the 'include_path' is.   http://us2.php.net/manual/en/function.phpinfo.php
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Assisted Solution

by:rinfo
rinfo earned 133 total points
ID: 39855555
php info will only tell what include_path is and will search that directory for the include which does not have a path.
As its not being able to find required file, and include does not mention any path, it is
evident that , if at all application was running ok earlier in some other location, config.php
some how is missing. Best way to check by  creating  a dummy config file have  in root directory , it will certainly fail on not being found config entries but you will be assured that
file is missing and you have to reconstruct it.
0
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 50 total points
ID: 39855746
Have a look at your Apache error logs. It will show you in there where the file is being loaded from, and should also show your include path it's trying to use.
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 0 total points
ID: 39857699
Ok, so the situation went something like this:
File A.php in folder X is the main file for running the app.
File B.php in folder X/Y is used by file A.php with a require_once("Y/B.php") call
File C.php in folder X/Y is used by file B.php with a require_once("C.php") call
File D.php in folder X/Z is called directly, and also requires file B.php. Unfortunately, when file B.php does its require_once("C.php") call, PHP is looking in folder X/Z for C.php but it's actually in folder X/Y

Normally, you'd just get a file not found error, but in my case the file was being found elsewhere on the server.

The solution is described here:
http://yagudaev.com/posts/resolving-php-relative-path-problem/

The require_once calls should include the path of the file currently running, which is obtained like this:
require_once(dirname(__FILE__)."/C.php");

This fixed the issue, without needing to find the file that was being loaded.

I can confirm however that I did find the file being loaded unintentionally in a different folder that was defined in the include_path value as shown by phpinfo(). Thanks all for your help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 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