[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

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

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
Terry Woods
Asked:
Terry Woods
6 Solutions
 
Cornelia YoderArtistCommented:
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
 
Dan CraciunIT ConsultantCommented:
Notepad++ has the same ability, and supports regular expressions.
So does WinGrep...

@TerryAtOpus: What does the  "include_path" say?

HTH,
Dan
0
 
Dave BaldwinFixer of ProblemsCommented:
'phpinfo()' will tell you what the 'include_path' is.   http://us2.php.net/manual/en/function.phpinfo.php
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rinfoCommented:
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
 
Chris StanyonCommented:
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
 
Terry WoodsIT GuruAuthor Commented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now