Problem with includes
Moderator: General Moderators
-
TwinkiE_HunteR-G
- Forum Newbie
- Posts: 14
- Joined: Tue Sep 17, 2002 8:44 am
Problem with includes
Ok, IM using PWS at home with PHP 4.2.1 on a Windows 98 machine.
My host (Portland Ltd) is running apache on AIX i believe. Now, at home (or work), I am working on a small website. But, whenever I include something in the files at home, it seems that I have to give the relative path to the files that are included in the include file from the file I am including from. Ugh. Let me try to clarify..
All includes are in /Foo/inc
/Foo/Bar/index.php
- includes table.inc
-table.inc includes blah.css
Now, I use include("../inc/table.inc"); and table.inc gives me an error saying it cant find blah.css.
In order for it to see blah.css, I would have to change the include in blah.css to ../inc/blah.css, but I dont want to do that because I want to include tables.inc in other files as well...
On my host, this is no problem. It seems to include from the included files path, not the first documents.
Does anyone understand what Im trying to say? because im pulling my hair out here, I know there has to be an answer, and more than likely the most simple answer.
If you can help, please do! I would greatly appreciate it.
Thanks
-TwinkiE
kng_nothing@yahoo.com
My host (Portland Ltd) is running apache on AIX i believe. Now, at home (or work), I am working on a small website. But, whenever I include something in the files at home, it seems that I have to give the relative path to the files that are included in the include file from the file I am including from. Ugh. Let me try to clarify..
All includes are in /Foo/inc
/Foo/Bar/index.php
- includes table.inc
-table.inc includes blah.css
Now, I use include("../inc/table.inc"); and table.inc gives me an error saying it cant find blah.css.
In order for it to see blah.css, I would have to change the include in blah.css to ../inc/blah.css, but I dont want to do that because I want to include tables.inc in other files as well...
On my host, this is no problem. It seems to include from the included files path, not the first documents.
Does anyone understand what Im trying to say? because im pulling my hair out here, I know there has to be an answer, and more than likely the most simple answer.
If you can help, please do! I would greatly appreciate it.
Thanks
-TwinkiE
kng_nothing@yahoo.com
-
TwinkiE_HunteR-G
- Forum Newbie
- Posts: 14
- Joined: Tue Sep 17, 2002 8:44 am
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
I use PWS with Windows 2000 and PHP 4
and here is how I do my includes with no problem
how are you including your files? are you saying your trying to include files from included files?
and here is how I do my includes with no problem
Code: Select all
<?php
require_once('inc/top.php');
?>how are you including your files? are you saying your trying to include files from included files?
-
TwinkiE_HunteR-G
- Forum Newbie
- Posts: 14
- Joined: Tue Sep 17, 2002 8:44 am
Ok.
All my includes are in Test/inc
I have Another directory for the site Test/Blah/here
Now, in Test/Blah/here i have a file foo.php
In foo.php i include bar.inc by include("../../inc/bar.inc");
Now, in bar.inc I include another file called woo.inc by include("woo.inc"); since bar.inc and woo.inc are in the same /Test/inc directory.
Now, when I include the file /Test/inc/bar.inc in file /Test/Blah/here/foo.php, I get an error saying it cant find bar.inc
So basically what I need to do is have the include files either
1. include the files they need before including into the first file.
or
2. Have the include files act as if they were in their own directory when being included.
I looked all through the configuration file, and the manual, but couldnt really find anything to address this.
All my includes are in Test/inc
I have Another directory for the site Test/Blah/here
Now, in Test/Blah/here i have a file foo.php
In foo.php i include bar.inc by include("../../inc/bar.inc");
Now, in bar.inc I include another file called woo.inc by include("woo.inc"); since bar.inc and woo.inc are in the same /Test/inc directory.
Now, when I include the file /Test/inc/bar.inc in file /Test/Blah/here/foo.php, I get an error saying it cant find bar.inc
So basically what I need to do is have the include files either
1. include the files they need before including into the first file.
or
2. Have the include files act as if they were in their own directory when being included.
I looked all through the configuration file, and the manual, but couldnt really find anything to address this.
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
well hope this helps.. I tested it real quick and heres what I came up with
the subincludes seem to only work going down the directory not back up
so I have a page called MAIN.php
now in MAIN.php I have a include
in INC.php I have
in test/inc2.php I have
that works fine now if I change that first include to test/inc.php and in test/inc.php I try and do ../inc2.php it fails so it looks like you can't include files within include files if they go back up the directory. You should test it on your system as well, see what you come up with.
the subincludes seem to only work going down the directory not back up
so I have a page called MAIN.php
now in MAIN.php I have a include
Code: Select all
<?php
<?php
include('inc.php');
?>
?>Code: Select all
<?php
<?php
echo 'Jim1';
include('test/inc2.php');
?>
?>Code: Select all
<?php
<?php
echo '<BR><BR>Jim2';
?>
?>- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
You can use "include_path" parameter of php.ini.
PHP looks fo the include()/require()/include_once()/require_once() files in this path.
See PHP man:
http://www.php.net/manual/en/printwn/co ... clude-path
For your local php setup, you can set:
And from other files (what so ever may be their path) u can simply code:
One important thing is, u should always use .php extension for u r include files also. Because if someone types in the complete include file path, he/she will get to see the include file contents.
For u r setup, try this in browser:
http://<yourdomain>/Test/inc/bar.inc
should show up the source code.
You can use "include_path" parameter of php.ini.
PHP looks fo the include()/require()/include_once()/require_once() files in this path.
See PHP man:
For your local php setup, you can set:
Code: Select all
include_path=".:Test/inc"Code: Select all
<?php
include( 'bar.inc' );
?>One important thing is, u should always use .php extension for u r include files also. Because if someone types in the complete include file path, he/she will get to see the include file contents.
For u r setup, try this in browser:
http://<yourdomain>/Test/inc/bar.inc
should show up the source code.