473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

include file path problem

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
10 1927
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: Marcus | last post by:
Hello, I am having problems with an include statement. I'm setting a session variable flag and then including a file, and in that include file I have a check at the top to make sure that the...
3
by: rajuvk | last post by:
I am setting up a website with a number of folders like: / (the document root) /user /admin/ /content in the /user folder there is a flie "userlogged.php", which I want to include in every...
4
by: michaaal | last post by:
I have two folders in my website... Folder1 (this is where my #include file is, this is where the style.css is) --Folder2 (Folder2 is inside of Folder1) Folder2 contains a file that has...
2
by: Robizzle | last post by:
I'm working on a very simple script that logs the ip address, time of hit, and os/browser information and currently it works every time. The problem is getting the script included into my html...
6
by: alan | last post by:
Dear all, I have written my own function by C. And my development platform is W2k with VC6.0. Then I also defined a header file to extern declare this function. After that, I include this...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.