Page 1 of 1

Problem with includes

Posted: Tue Sep 17, 2002 8:44 am
by TwinkiE_HunteR-G
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

Posted: Tue Sep 17, 2002 9:05 am
by Wayne
the easy solution would be to give the absolute path to the include files.

Posted: Tue Sep 17, 2002 9:20 am
by TwinkiE_HunteR-G
The only problem with that is I would have to go through all of my pages and change them every time I wanted to test them on my computer and then upload them to the server. Surley there has to be another way.

Posted: Tue Sep 17, 2002 11:00 am
by Takuma
I don't think you can use absolute address in include...

Posted: Tue Sep 17, 2002 11:44 am
by Johnm
TwinkiE_HunteR-G,
Link the directory.


Takuma
I don't think you can use absolute address in include...
Why not? Don't think... know or ask.

Direwolf.

Posted: Tue Sep 17, 2002 11:55 am
by JPlush76
I use PWS with Windows 2000 and PHP 4

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?

Posted: Tue Sep 17, 2002 12:04 pm
by TwinkiE_HunteR-G
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.

Posted: Tue Sep 17, 2002 12:21 pm
by JPlush76
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

Code: Select all

<?php
<?php
 include('inc.php');
?>
?>
in INC.php I have

Code: Select all

<?php
<?php
 echo 'Jim1';
 include('test/inc2.php');
?>
?>
in test/inc2.php I have

Code: Select all

<?php
<?php
 echo '<BR><BR>Jim2';
?>

?>
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.

Posted: Tue Sep 17, 2002 3:40 pm
by Takuma
What I meant was that when I tried it before it didn'T work :o

Posted: Wed Sep 18, 2002 1:50 pm
by gite_ashish
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:

:arrow: http://www.php.net/manual/en/printwn/co ... clude-path


For your local php setup, you can set:

Code: Select all

include_path=".:Test/inc"
And from other files (what so ever may be their path) u can simply code:

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.