473,805 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("d blib/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 1952
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("d blib/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*******@attgl obal.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("d blib/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("d blib/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*******@attgl obal.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("d blib/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("d blib/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*******@attgl obal.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("d blib/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('inclu de/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("d blib/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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5134
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 relative NOT to the immediate script that is including it, but is relative to the top-level calling script. In practice, this means that you have to constantly worry and adjust paths in includes, based on the startup scripts that call these...
2
1889
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 session variable is set, otherwise I stop executing and redirect. My problem is that this works if I use a relative path to the include file, but not if I use the full path. If I use the full path, it does not read the session flag as being set,...
3
6948
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 file. If in the file "/content/index.php", if I use the relative path and place the include like this "../user/userlogged.php", it will work fine. But when I use the absolute path like "/user/userlogged.php", it is not working ?. I have
4
2885
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 this #include statement... <!--#include file="../include.inc"-->
2
1619
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 document (so I can log everyone that visits that page.) Here is my code and how the files are organized: I know some of the code is probably sloppy, these are literally the first php files i've written and I just started yesterday from...
6
7068
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 header file. The function is stored in C:\temp\myfun.c int func(){ return 1;
5
2513
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 very carefully define the order in which paths are searched with command line options on the compiler. Both can cause problems, especially when dealing with complex software distributions. It occurs ot me that by extending the C include...
3
2713
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 directories contain a file named "cppfile1.h". In my main project I #include "cppfile1.h". I rely on the order of paths in additional include directories list to get file cppfile1.h from ProjectA and
2
3017
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 this: #include "pathname/file"
6
2129
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file = ...\includes\StaffingHeaders.inc -->" </Script> <%=ClientName%> ****************************************************************************
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.