By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

include file path problem

P: n/a
Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem
Aug 20 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Raheem wrote:
Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem
The first one looks in the current directory. The second one looks in
one directory lower. It looks like your file setup is different between
your test and production servers.

BTW - I always use absolute paths instead of relative. That way if I
move a file that includes something else, it still works, i.e.

include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');

This looks for the file in the dblib of the web root directory.

P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
multipost.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 20 '08 #2

P: n/a
Jerry Stuckle wrote:
Raheem wrote:
>Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem

The first one looks in the current directory. The second one looks in
one directory lower. It looks like your file setup is different between
your test and production servers.

BTW - I always use absolute paths instead of relative. That way if I
move a file that includes something else, it still works, i.e.

include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');

This looks for the file in the dblib of the web root directory.

P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
multipost.

Huh?

The first one looks for the dblib directory in the current directory and
then looks for dbcon.php. It is equivalent to ./dblib/db_con.php.

The second one looks for a directory, dblib, which is on the same level
as the current directory. IOW, it goes up one level and then tries to
find the directory dblib and in that directory looks for db_con.php.

Apparently, since the first one worked and the second didn't, the dblib
directory must be in the current directory.
Aug 20 '08 #3

P: n/a
Thanks for your help guys! I have a better understanding now. The
solution was to use symlinks. Full solution listed in
http://groups.google.com/group/alt.p...d7f522e?hl=en#
Aug 20 '08 #4

P: n/a
True, if the live site needs to be moved, its going to be a major
problem. But due to contractual limitations, my work cannot change the
client's site structure etc. That is why I need the dev env to be
exact as the live env - so that I can port changes.
Aug 20 '08 #5

P: n/a
sheldonlg wrote:
Jerry Stuckle wrote:
>Raheem wrote:
>>Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem

The first one looks in the current directory. The second one looks in
one directory lower. It looks like your file setup is different
between your test and production servers.

BTW - I always use absolute paths instead of relative. That way if I
move a file that includes something else, it still works, i.e.

include ($_SERVER['DOCUMENT_ROOT'] . '/dblib/db_con.php');

This looks for the file in the dblib of the web root directory.

P.S. If you MUST post to multiple newsgroups, please crosspost. Don't
multipost.


Huh?

The first one looks for the dblib directory in the current directory and
then looks for dbcon.php. It is equivalent to ./dblib/db_con.php.

The second one looks for a directory, dblib, which is on the same level
as the current directory. IOW, it goes up one level and then tries to
find the directory dblib and in that directory looks for db_con.php.

Apparently, since the first one worked and the second didn't, the dblib
directory must be in the current directory.
Which is basically what I said.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 20 '08 #6

P: n/a
Raheem ha scritto:
Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem

A nice solution I use for keeping includes out of the way is to set two
directives (they can be set in both php.ini and vhost file)
Say your site has its root in /var/www/sitename/htdocs
You create a dir which is: /var/www/sitename/includes
then you set
open_basedir('/var/www/sitename')
And
include_path='/var/www/sitename/includes';

So your includes cannot by any means be served on their own, since they
are out of the directory tree served by your webserver
Just a little bit safer
:)
Aug 21 '08 #7

P: n/a
Motosauro wrote:
Raheem ha scritto:
>Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem


A nice solution I use for keeping includes out of the way is to set two
directives (they can be set in both php.ini and vhost file)
Say your site has its root in /var/www/sitename/htdocs
You create a dir which is: /var/www/sitename/includes
then you set
open_basedir('/var/www/sitename')
And
include_path='/var/www/sitename/includes';

So your includes cannot by any means be served on their own, since they
are out of the directory tree served by your webserver
Just a little bit safer
:)
You don't even need access to the php.ini file (not available at most
shared hosts). PHP can access anything on the file system your host
allows you to - and the better ones will allow you to access one level
below the web root. So you can use something like:

include ($_SERVER['DOCUMENT_ROOT'] . '/../include/myinclude.php');

Assuming your document root points to /var/www/example/html, this gets
the file from /var/www/example/include.

And if your hosting company doesn't give you access, you're probably
better off getting another hosting company, anyway.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 21 '08 #8

P: n/a
Jerry Stuckle ha scritto:
Motosauro wrote:
>Raheem ha scritto:
>>Hello,

I built a development version of a live website on my hosted account.
However the development version is having problems with finding
include files. After troubleshooting I was able to resolve the issue
by removing the ../ from the beginning of the include file path. But
now I am looking at making this modification hundreds of times in all
kinds of files. I'd like to keep the dev env similar to the live env
so I can port changes easily. Below is an example of working and non-
working include file definitions:

working - include_once("dblib/db_con.php");
non-working - include_once("../dblib/db_con.php");

But I dont understand why this would work in one server and not the
other. Is there some kind of setting in htaccess or php.ini that would
affect this? The dev env is running php 5.2.6. Appreciate your help.

- Raheem


A nice solution I use for keeping includes out of the way is to set
two directives (they can be set in both php.ini and vhost file)
Say your site has its root in /var/www/sitename/htdocs
You create a dir which is: /var/www/sitename/includes
then you set
open_basedir('/var/www/sitename')
And
include_path='/var/www/sitename/includes';

So your includes cannot by any means be served on their own, since
they are out of the directory tree served by your webserver
Just a little bit safer
:)

You don't even need access to the php.ini file (not available at most
shared hosts). PHP can access anything on the file system your host
allows you to - and the better ones will allow you to access one level
below the web root. So you can use something like:

include ($_SERVER['DOCUMENT_ROOT'] . '/../include/myinclude.php');

Assuming your document root points to /var/www/example/html, this gets
the file from /var/www/example/include.

And if your hosting company doesn't give you access, you're probably
better off getting another hosting company, anyway.
Right:
One need to remember to set (or check) the open_basedir directive
I'd rather point to *include('include/myinclude.php')* though
Aug 21 '08 #9

P: n/a
Everyone, thanks for the comments. Jensen the live env uses
include_once("../dblib/db_con.php"). But that path does not work on
the DEV env unless changed to include_once("dblib/db_con.php"). Using
symlinks, I am able to get the DEV site working without modifying
hundreds of references to the include files and also keep the dev and
live files the same. Your fullpath suggestion makes sense but in this
instance (adding functionality to a site built by someone else);
changing to a fullpath syntax would require lots of code changes,
which I would not be paid for, and could potentially break the site. I
am leery about changing someone else's code (esp undocumented code)
unless I absolutely have to.
Aug 22 '08 #10

P: n/a
Raheem wrote:
Everyone, thanks for the comments. Jensen the live env uses
include_once("../dblib/db_con.php"). But that path does not work on
the DEV env unless changed to include_once("dblib/db_con.php"). Using
symlinks, I am able to get the DEV site working without modifying
hundreds of references to the include files and also keep the dev and
live files the same. Your fullpath suggestion makes sense but in this
instance (adding functionality to a site built by someone else);
changing to a fullpath syntax would require lots of code changes,
which I would not be paid for, and could potentially break the site. I
am leery about changing someone else's code (esp undocumented code)
unless I absolutely have to.
Then change your development environment to match that of the production
system (that's how you should have it set up, anyway). You don't need
symlinks if the two are set up the same way.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 22 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.