GetDotted Domains

Viewing Thread:
"PHP include() inconsistency"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Thu 17/02/05 at 11:53
Regular
"NULL"
Posts: 1,384
I have built a web site on my Windows PC running Apache, PHP5 and MySQL. On uploading to a Linux server running Apache, PHP4 and MySQL, it broke.

The problem is with the include() functions. On Windows, all includes are relative to the top level file, so if I include B in A, and C in B, then I must specify the path of C in B with respect to A.

However, when I uploaded to the server, it wanted some of the paths relative to the top level and some relative to the current level. It seems totally inconsistent. Any ideas why? Have they changed how includes work in PHP5?
Fri 18/02/05 at 10:59
Regular
"NULL"
Posts: 1,384
I've added you...you can edit your post to delete your email address now.
Fri 18/02/05 at 03:20
Regular
"Devil in disguise"
Posts: 3,151
Nimco wrote:
> Any ideas? I'm sure PHP used to parse URLs relative to the current
> file being executed and not the top level file - was that not the
> case?
>

Actually did some more testing, PHP supports both (tried using 5.0.2 and 4.3.9), includes appear to work with paths relative to the current script and the working directory (location of the top level script). The only exception is if the include starts with .. and then it looks relative to the working directory only. And thats consistent with what the manual says too.
Basically the behaviour you have on your linux server is correct as best I can see from the includes you've shown.

File - admin/blocks/header.php



On your PHP 5, if you have include("menus/main.php"); instead it really wont work? If not, looks like its corrupt in some way.

Btw, also read about a work around for this type of thing which seems to work quite nicely. Just put dirname(__FILE__)."/" at the front of all your include paths and you'll always be dealing with paths relative to the current script. So if include("menus/main.php"); doesn't work in PHP 5, maybe include(dirname(__FILE__)."/"."menus/main.php"); does.
Thu 17/02/05 at 22:57
Regular
"NULL"
Posts: 1,384
These are the php.ini values from the remote server:

include_path = .:/usr/share/pear
open_basedir = /data/www/

and on my Windows machine:

include_path = .;C:\php5\pear
open_basedir = no value

Any ideas? I'm sure PHP used to parse URLs relative to the current file being executed and not the top level file - was that not the case?

Also, do you use MSN Messenger?
Thu 17/02/05 at 22:37
Regular
"Devil in disguise"
Posts: 3,151
Well, all I can add is that I cant find anything in the documentation either. I've just tried PHP 4 and 5 on windows and they both behave the same way regarding includes as best I can see but of course thats not conclusive as we could be running different versions of 4 & 5 (I haven't updated mine in a while).

The documented behaviour is that paths should be relative to the top level file being executed, ie what your windows machine is doing. As for it being inconsistent on the linux server, you might be just getting lucky especially likely if your include_path has both the document root and '.' .
Thu 17/02/05 at 21:02
Regular
"NULL"
Posts: 1,384
But what would cause it to act differently between the two servers? Is it a PHP4 to PHP5 change? If so, I couldn't find anything in the documentation.

And it doesn't appear to be a php.ini or Apache httpd.conf setting - we tried changing any relevant settings on the remote server to match a server known to work the same.

Even within scripts being parsed on the remote server, it is handling them differently - look at the way it links some of the includes - it's just plain inconsistent.
Thu 17/02/05 at 20:17
Regular
"Devil in disguise"
Posts: 3,151
Only thing PHP related I can see that might cause that behaviour is this from the docs on include:

"If filename begins with ../, it is looked only in include_path relative to the current working directory."

If include_path is defined to something other than the document root then you'd get that effect. I guess the way around the differences it to make the include paths absolute.
Thu 17/02/05 at 19:00
Regular
"NULL"
Posts: 1,384
I have shown below the include commands in question

File - admin/index.php


File - admin/blocks/header.php



File - admin/verifylogin.php


File - includes/dbconnect.php
File - admin/blocks/menus/main.php

Those work fine on my Windows setup with PHP5, but on the Linux server with PHP4 they have to be changed to:

File - admin/index.php


File - admin/blocks/header.php


File - admin/verifylogin.php


File - includes/dbconnect.php
File - admin/blocks/menus/main.php

It just seems really inconsistent.
Thu 17/02/05 at 14:16
Regular
"Devil in disguise"
Posts: 3,151
Can we see all the include statements?

You could get that effect from the apache configuration which to me seems a more likely cause.
Thu 17/02/05 at 11:53
Regular
"NULL"
Posts: 1,384
I have built a web site on my Windows PC running Apache, PHP5 and MySQL. On uploading to a Linux server running Apache, PHP4 and MySQL, it broke.

The problem is with the include() functions. On Windows, all includes are relative to the top level file, so if I include B in A, and C in B, then I must specify the path of C in B with respect to A.

However, when I uploaded to the server, it wanted some of the paths relative to the top level and some relative to the current level. It seems totally inconsistent. Any ideas why? Have they changed how includes work in PHP5?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

I am delighted.
Brilliant! As usual the careful and intuitive production that Freeola puts into everything it sets out to do. I am delighted.
Easy and free service!
I think it's fab that you provide an easy-to-follow service, and even better that it's free...!
Cerrie

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.