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
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

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
Technology Partners: 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!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
i am unable to add data to mysql database 6 51
How to use session variables in php? 22 46
CURL sending XML without spaces PHP 5 33
Compiling PHP with Curl plus protocols 8 22
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

749 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