How to include file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostinfog
Forum Newbie
Posts: 8
Joined: Wed Apr 26, 2006 4:22 am

How to include file

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Start it off with $_SERVER['DOCUMENT_ROOT'] maybe?
lostinfog
Forum Newbie
Posts: 8
Joined: Wed Apr 26, 2006 4:22 am

Many thanks to your quick answer and it works!

Post by lostinfog »

This question must be a very common issue in php development. What's the normal way to cope with this?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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');
(#10850)
Post Reply