Page 1 of 1

How to include file

Posted: Sat May 06, 2006 12:18 am
by lostinfog
I have an include file. In this include file, other files are included.
It doesn't work when this file is included in many files under different directories.
I try to include absolute path in this include file. But it doesn't work.
I also try set_include_path(), it doesn't work yet.
What should I do?
TIA!

My case example:

/test/functions.php

Code: Select all

include('../include/config.inc.php');
include('../include/db.inc.php');
This functions.php need to be included in /index.php and /test/index.php.

Posted: Sat May 06, 2006 12:28 am
by feyd
Start it off with $_SERVER['DOCUMENT_ROOT'] maybe?

Many thanks to your quick answer and it works!

Posted: Sat May 06, 2006 12:46 am
by lostinfog
This question must be a very common issue in php development. What's the normal way to cope with this?

Posted: Sat May 06, 2006 1:24 am
by hawleyjr
lostinfog wrote:This question must be a very common issue in php development. What's the normal way to cope with this?
feyd wrote:Start it off with $_SERVER['DOCUMENT_ROOT'] maybe?
:wink: :wink: :wink:

Posted: Sat May 06, 2006 2:14 am
by Christopher
Your name reminds me of Kurosawa:

Code: Select all

include($_SERVER['DOCUMENT_ROOT'] . '/include/config.inc.php');
include($_SERVER['DOCUMENT_ROOT'] . '/include/db.inc.php');