Jump to content

PHP Include Problem - Includes from one site showing on another site - IIS


wayner

Recommended Posts

Hi,

 

My first post here is a cry for help :)

 

I have a Windows 2003 server running IIS6/PHP5, the server hosts multiple web sites.

 

The problem is include files that are for site A are showing on site B (each site having its own includes as part of the site files in its own site folder), though not every time, its very random, sometimes the correct includes show, sometimes ones from another site on the same server. This only occurs where the include files for both sites have the same name, such as 'inc-header.php' for example.

 

I can only assume PHP is caching includes and because they have the same name is showing the wrong one on other sites sometimes, if I rename them to something unique then the problem goes away, but its not a practical solution to rename all include files to unique names so I find myself looking for a 'real' fix.

 

I have a feeling its to do with the include_path in the php.ini, but right now its disabled with a semi-colon, and I don't want to set one as I have no global includes, all includes are site specific.

 

Any help would be very much appreciated!

 

Phil

 

Link to comment
Share on other sites

Check what your include_path setting is using a phpinfo(); statement. A setting commented out in php.ini does not mean that php is not using a default.

 

Post an actual example of the include statement that is experiencing this problem. Knowing how the file is being specified in the statement narrows down where the problem is.

 

Also post relevant information like, the php version, is php running as a server module or a CGI application, and the file system paths where the script and the included files are at.

Link to comment
Share on other sites

Thanks for your reply.

 

In my php.ini, the include_path setting looks like this:

 

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

;

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

 

When I view phpinfo, it shows this:

 

                Local Value      Master Value

include_path .;C:\php5\pear .;C:\php5\pear

 

The server is running Windows 2003 with IIS6, PHP version is 5.2.5.

 

A typical include statement used on a site would look like this:

 

<?php require_once('inc-header.php'); ?>

 

This statement should include the file thats in the same directory as the file that is calling it, irrespective of the include_path setting, as PHP should always look locally first for an include file.

 

Note that if I use a full file system path to the include file (such as d:/sites/sitea/www/inc-header.php rather than just the inc-header.php) the problem goes away.

 

In all circumstances where this happens both the include files and the files calling the include files are all in the root of the site directory.

 

The problem arises when other sites have include files of the same name, they randomly get shown on each others sites in place of the local copy of the include, sometimes its fine other times you get the wrong include being included from a completely different site on the server.

Link to comment
Share on other sites

This statement should include the file thats in the same directory as the file that is calling it, irrespective of the include_path setting, as PHP should always look locally first for an include file.
You would think that is the way it should work, but php.net has other ideas.

 

Php.net has a long history of problems with the _once version of include/require and with getting the include/require to work as expected.

 

The current definition for just a file or a path/file (without any leading ./ or ../) is -

 

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script

 

Depending on what your server has for include_path and what it is setting the CWD to, you can expect unexpected results. I am going to guess that the CWD is not being set properly on your server.

 

I recommend that to avoid problems with how php.net thinks this should work, that you use an absolute file system path and avoid using the _once version -

 

require($_SERVER['DOCUMENT_ROOT'] . "/path_to_your_include/include_file.php");  

Link to comment
Share on other sites

I didnt think PHP was so flaky
Only certain parts of it, but the frequency of new simple to avoid problems seems to be increasing. I have seen new bugs where the "programmer" clearly did not have any direction, definition, planning, knowledge, or the skills to be working on the core code.
Link to comment
Share on other sites

  • 2 years later...

I have an identical problem to the OP, and really want to be able to clone sites without editing-in absolute paths to includes. Has there been any progress in resolving this particular 'flake'?

 

Cheers,

 

Ken

 

Actually, many thanks to PFMaBiSmAd, his solution won't preclude cloning, but I found this post useful two years on so... bump  8^)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.