473,327 Members | 2,012 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,327 software developers and data experts.

Include and sub-includes (correction)

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
11 2966
"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
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
"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
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

"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
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
"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
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

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

Similar topics

6
by: Henk ten Bos | last post by:
Hi all, is there anyone who knows of a way in VB6 to have include-files (like in C: include <include.h>) ? thanks! Henk
4
by: Tom Bates | last post by:
Possible? It seems nobody knows how... :-) Tom
1
by: Susan Cranford | last post by:
I know this is simple but I'm new with it and can't see it. I am calling this sub from an ASP page right after the <html> tag as: <!-- #include file="genproc.inc"--> Then I call the sub below...
2
by: Steven K | last post by:
Hello, I have an include file (../../Connections/pricex.inc). That I use to declare my variables and build my connection string. I tried using the following, but got the error: Compiler Error...
2
by: brett | last post by:
I need to include some webpages and am doing this in my index page: <%@ Register TagPrefix="mysite" TagName="section1" Src="/sub/section1.ascx" %> <%@ Register TagPrefix="mysite"...
4
by: Al Franz | last post by:
Editing a script that has a "sub printheader" and "sub printfooter" routine before and after it creates a web page with a message. I would like to customize this script so that I can have my own...
10
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
4
by: bluebillow | last post by:
I am a new perl programer and I meet a question. I have a perl file test_1.pl like: #!/usr/bin/perl sub Test; sub Test { printf "==========================Hello, perl.\n"; return...
3
by: =?Utf-8?B?VG9kZCBEb2JtZXllcg==?= | last post by:
I am working on developing a program using Visual Studio 2003 but am having problems getting my program to find my GL.h and GLU.h, and I am guessing it will have the same problems trying to link to...
25
by: Mark | last post by:
so, i'm making a website. let's say i have header.php, footer.php and content.php. now in index.php I simply want to include the 3 pages. easy enough to do. but let's say the user navigates to...
0
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: 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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.