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

Include and sub-includes (correction)

P: n/a
Oups! I did a typing error in my last post. Fixed.
-----------

Hello all,

We are currently changing our web server and, in the process, updating PHP
version from 4.3.0 to 4.3.5. The problem we've got is that our way to
include some files in other ones is no more working properly. The message we
are getting looks like: "PHP Warning: main(..\db.inc.php): failed to open
stream: No such file or directory in ..."

Say we have this file structure:

myApplication (dir)
index.php
include (dir)
db.inc.php
authentification (dir)
user.inc.php
login.php
- user.inc.php includes db.inc.php calling "include('..\db.inc.php')"
- both login.php and index.php includes user.inc.php
- index.php calls "include('include\authentification\user.inc.ph p')"
- login.php calls "include('user.inc.php')" <-- Corrected here

I know I could solve this problem by making those the includes absolute
instead of relative but I would prefer to let it relative for some
developement reason. myApplication actually contains many other files
calling "include('..\db.inc.php')" so I don't want to move this file.

Our old configuration seems to include child-includes in their parents
before including the parent-include in the main file. Now it seems to
include parent before include childs.

Any one has an idea why it's no more working and what I could do solve this?

Yannick


Jul 17 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Yannick Turgeon" <no****@nowhere.com> wrote in
news:IF*******************@news20.bellglobal.com:
We are currently changing our web server and, in the process, updating
PHP version from 4.3.0 to 4.3.5. The problem we've got is that our way
to include some files in other ones is no more working properly. The
message we are getting looks like: "PHP Warning: main(..\db.inc.php):
failed to open stream: No such file or directory in ..."


"{$_SERVER['DOCUMENT_ROOT']}/db.inc.php" in place of "../db.inc.php" should
do wonders; now your includes no longer have to care where in the
filesystem they are.
Jul 17 '05 #2

P: n/a
Hello Eric, thanks to reply.

The problem with this solution is:
1- My developement environment is in a different directory on the same
server. That way, I would have to change every reference to included files
when I send new version to production.
2- $_SERVER['DOCUMENT_ROOT'] is not available in IIS and I don't know any
equivalent.

The way I finaly "solved" my situation is by checking if I am in the
development directory or not and calling the absolute path depending the
situation. I'm not satisfied with this though. A better solution would be
welcomed.

Yannick
"Eric Bohlman" <eb******@earthlink.net> wrote in message
news:Xn*******************************@130.133.1.4 ...
"Yannick Turgeon" <no****@nowhere.com> wrote in
news:IF*******************@news20.bellglobal.com:
We are currently changing our web server and, in the process, updating
PHP version from 4.3.0 to 4.3.5. The problem we've got is that our way
to include some files in other ones is no more working properly. The
message we are getting looks like: "PHP Warning: main(..\db.inc.php):
failed to open stream: No such file or directory in ..."
"{$_SERVER['DOCUMENT_ROOT']}/db.inc.php" in place of "../db.inc.php"

should do wonders; now your includes no longer have to care where in the
filesystem they are.

Jul 17 '05 #3

P: n/a
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:%i*********************@news20.bellglobal.com ...
Hello Eric, thanks to reply.

The problem with this solution is:
1- My developement environment is in a different directory on the same
server. That way, I would have to change every reference to included files
when I send new version to production.
2- $_SERVER['DOCUMENT_ROOT'] is not available in IIS and I don't know any
equivalent.

The way I finaly "solved" my situation is by checking if I am in the
development directory or not and calling the absolute path depending the
situation. I'm not satisfied with this though. A better solution would be
welcomed.


I didn't see your original email, but in what way is your original software
no longer working? Do you have the same include path set up in the new PHP's
ini file?

- Virgil
Jul 17 '05 #4

P: n/a
Hello Virgil,

Here is the original message.

Thanks for your time.

------------------------
Hello all,

We are currently changing our web server and, in the process, updating PHP
version from 4.3.0 to 4.3.5. The problem we've got is that our way to
include some files in other ones is no more working properly. The message we
are getting looks like: "PHP Warning: main(..\db.inc.php): failed to open
stream: No such file or directory in ..."

Say we have this file structure:

myApplication (dir)
index.php
include (dir)
db.inc.php
authentification (dir)
user.inc.php
login.php
- user.inc.php includes db.inc.php calling "include('..\db.inc.php')"
- both login.php and index.php includes user.inc.php
- index.php calls "include('include\authentification\user.inc.ph p')"
- login.php calls "include('user.inc.php')" <-- Corrected here

I know I could solve this problem by making those the includes absolute
instead of relative but I would prefer to let it relative for some
developement reasons, the main one being the fact that our development and
production environments ar on the same server in two different directories.
myApplication actually contains many other files
calling "include('include\db.inc.php')" so I don't want to move this file.

Our old configuration seems to include child-includes in their parents
before including the parent-include in the main file. Now it seems to
include parent before include childs.


"Virgil Green" <vj*@obsydian.com> wrote in message
news:up******************@newssvr22.news.prodigy.c om...
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:%i*********************@news20.bellglobal.com ...
Hello Eric, thanks to reply.

The problem with this solution is:
1- My developement environment is in a different directory on the same
server. That way, I would have to change every reference to included files when I send new version to production.
2- $_SERVER['DOCUMENT_ROOT'] is not available in IIS and I don't know any equivalent.

The way I finaly "solved" my situation is by checking if I am in the
development directory or not and calling the absolute path depending the
situation. I'm not satisfied with this though. A better solution would be welcomed.
I didn't see your original email, but in what way is your original

software no longer working? Do you have the same include path set up in the new PHP's ini file?

- Virgil

Jul 17 '05 #5

P: n/a

"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:cF*********************@news20.bellglobal.com ...
Hello Virgil,

Here is the original message.

Thanks for your time.

------------------------
Hello all,

We are currently changing our web server and, in the process, updating PHP
version from 4.3.0 to 4.3.5. The problem we've got is that our way to
include some files in other ones is no more working properly. The message we are getting looks like: "PHP Warning: main(..\db.inc.php): failed to open
stream: No such file or directory in ..."

Say we have this file structure:

myApplication (dir)
index.php
include (dir)
db.inc.php
authentification (dir)
user.inc.php
login.php
- user.inc.php includes db.inc.php calling "include('..\db.inc.php')"
- both login.php and index.php includes user.inc.php
- index.php calls "include('include\authentification\user.inc.ph p')"
- login.php calls "include('user.inc.php')" <-- Corrected here

I know I could solve this problem by making those the includes absolute
instead of relative but I would prefer to let it relative for some
developement reasons, the main one being the fact that our development and
production environments ar on the same server in two different directories. myApplication actually contains many other files
calling "include('include\db.inc.php')" so I don't want to move this file.

Our old configuration seems to include child-includes in their parents
before including the parent-include in the main file. Now it seems to
include parent before include childs.


As it turns out, I had seen this message somewhere and even recall replying
to it. Did you post it elsewhere?

Anyay, you didn't describe exactly what is not working. The only error
message you did give would imply that your include_path did not contain a
'.' entry to allow for relative addressing.

What are your errors (all of them, cut and paste or provide a link) and what
is your current include_path setting?

- Virgil
Jul 17 '05 #6

P: n/a
As it turns out, I had seen this message somewhere and even recall replying to it. Did you post it elsewhere?
No. I didn't.
Anyay, you didn't describe exactly what is not working. The only error
message you did give would imply that your include_path did not contain a
'.' entry to allow for relative addressing.
Has the error message pasted at the end is confirming it, the "." is part of
the include_path. And this setting is exactly the same as the old server.

What are your errors (all of them, cut and paste or provide a link) and what is your current include_path setting?


PHP Warning: main(..\db.inc.php): failed to open stream: No such file or
directory in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php
on line 4 PHP Warning: main(): Failed opening '..\db.inc.php' for inclusion
(include_path='.;c:\php4\pear') in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php
on line 4

This is a mystery for me. I've lost a lot of time to figure out this trouble
without success, so I would really appreciate to, at least, learn from that
even if I've "patched" it.

Yannick
Jul 17 '05 #7

P: n/a
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:58*********************@news20.bellglobal.com ...
As it turns out, I had seen this message somewhere and even recall replying
to it. Did you post it elsewhere?


No. I didn't.
Anyay, you didn't describe exactly what is not working. The only error
message you did give would imply that your include_path did not contain a '.' entry to allow for relative addressing.


Has the error message pasted at the end is confirming it, the "." is part

of the include_path. And this setting is exactly the same as the old server.

What are your errors (all of them, cut and paste or provide a link) and what
is your current include_path setting?


PHP Warning: main(..\db.inc.php): failed to open stream: No such file or
directory in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php
on line 4 PHP Warning: main(): Failed opening '..\db.inc.php' for

inclusion (include_path='.;c:\php4\pear') in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php
on line 4


What URL did you use when you got these messages? That will tell me what
your "current" directory is set to.

Oh, and what does the actual line of code look like? Does it have a forward
a backward slash? Even on a Windows server, you should use the forward slash
in code for a separator. It translates that for you to a backslash when
accessing the file system. the examples you provided earlier all had
backslashes and that would be interpreted, especially in a double quoted
string, as an escape character.

- Virgil
Jul 17 '05 #8

P: n/a
Yannick Turgeon wrote:
This is a mystery for me. I've lost a lot of time to figure out this trouble
without success, so I would really appreciate to, at least, learn from that
even if I've "patched" it.


I think maybe your trouble is that '.' stays put once a script starts
even if it includes other scripts in other directories.

Let's say Apache calls php to process the file
D:/Inetpub/wwwroot/main.php ==> '.' is set to D:/Inetpub/wwwroot

main.php includes 'admin/validate.php'
inside admin/validate.php
the '.' current directory is still D:/Inetpub/wwwroot and not
D:/Inetpub/wwwroot/admin

if validate.php now includes '../db.inc.php' it really refers to
D:/Inetpub/wwwroot/../db.inc.php = ie = D:/Inetpub/db.inc.php

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #9

P: n/a

"Virgil Green" <vj*@obsydian.com> wrote in message
news:II*****************@newssvr22.news.prodigy.co m...
"Yannick Turgeon" <no****@nowhere.com> wrote in message
news:58*********************@news20.bellglobal.com ...

Oh, and what does the actual line of code look like? Does it have a

forward a backward slash? Even on a Windows server, you should use the forward slash in code for a separator. It translates that for you to a backslash when
accessing the file system. the examples you provided earlier all had
backslashes and that would be interpreted, especially in a double quoted
string, as an escape character.


Correction on my part. The backslash will only be interpreted as an escape
instruction if an "escapable" character follows it.

- Virgil
Jul 17 '05 #10

P: n/a
> > > What are your errors (all of them, cut and paste or provide a link)
and
what is your current include_path setting?


PHP Warning: main(..\db.inc.php): failed to open stream: No such file or
directory in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php on line 4 PHP Warning: main(): Failed opening '..\db.inc.php' for
inclusion (include_path='.;c:\php4\pear') in
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php on line 4


What URL did you use when you got these messages? That will tell me what
your "current" directory is set to.


I'm calling:
D:\Inetpub\wwwroot\admin\develop\calendrier\index. php
which forward me, if I'm not logged in, to:
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\login.php

Both of these files include the file:
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\userAuth\UA_config.php
which include:
D:\Inetpub\wwwroot\admin\develop\calendrier\includ e\db.inc.php

The actual line of code in UA_config.php is:
include_once("..\\db.inc.php");

I tried with:
include_once("../db.inc.php");
and it does the same. I didn't know that the "/" in paths was translated to
"\" in Windows. I'll use them in the futur.

More to read on my reply to Pedro...

Yannick

P.S. Sorry Virgil I just replied to you personnaly by error.
Jul 17 '05 #11

P: n/a
You got it all Pedro,

My problem seems to be related to the current directory. But what is
important is the fact that all this was working fine on our old serveur:
W2K, IIS ???, PHP 4.3.0 (now we have W2K, IIS ???+, PHP 4.3.0) and with the
same config (looks like though). The current directory seems to stay the
same in the process of including files when before is wasn't.

Now I'm cooked since an include file, including another one cannot be
included by different page, in different directories using relative path.

See my last reply to Virgil for more info.

Thanks for your time.

Yannick

"Pedro Graca" <he****@hotpop.com> wrote in message
news:c5*************@ID-203069.news.uni-berlin.de...
Yannick Turgeon wrote:
This is a mystery for me. I've lost a lot of time to figure out this trouble without success, so I would really appreciate to, at least, learn from that even if I've "patched" it.


I think maybe your trouble is that '.' stays put once a script starts
even if it includes other scripts in other directories.

Let's say Apache calls php to process the file
D:/Inetpub/wwwroot/main.php ==> '.' is set to D:/Inetpub/wwwroot

main.php includes 'admin/validate.php'
inside admin/validate.php
the '.' current directory is still D:/Inetpub/wwwroot and not
D:/Inetpub/wwwroot/admin

if validate.php now includes '../db.inc.php' it really refers to
D:/Inetpub/wwwroot/../db.inc.php = ie = D:/Inetpub/db.inc.php

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :

Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.