Page 1 of 1

Absolute path

Posted: Fri Mar 24, 2006 1:53 pm
by Nicofast
Hi!

I'm a newbie with PHP, and I'm creating my web. The problem is that I need the home path of the server to call my functions, independently where is the call to them. Anyone can help me?

Thank you!

Posted: Fri Mar 24, 2006 2:07 pm
by Christopher
There are many ways to achieve that. Here are a couple:

Code: Select all

define('BASE_DIR', '/path/to/my/files/');

include BASE_DIR . 'myscript.php';
Or

Code: Select all

define('BASE_DIR', '/path/to/my/files/');
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . BASE_DIR);

include 'myscript.php';

Posted: Fri Mar 24, 2006 4:19 pm
by feyd
could potentially use $_SERVER['DOCUMENT_ROOT'] too

Posted: Fri Mar 24, 2006 4:22 pm
by hawleyjr
feyd wrote:could potentially use $_SERVER['DOCUMENT_ROOT'] too
Take Feyd's advice. This way if you ever switch servers you won't have to worry about changing the document root :)

Posted: Fri Mar 24, 2006 4:36 pm
by matthijs
or use both ? :)

Code: Select all

$path = $_SERVER['DOCUMENT_ROOT'] . BASEURL;
header('Location: $path');
(in which BASEURL is not an absolute server path of course)

Or is that stupid? :?

Posted: Fri Mar 24, 2006 4:55 pm
by feyd
ignoring the redirection, it's fine. I do it myself in many projects.

Thank you to all

Posted: Tue Mar 28, 2006 8:11 am
by Nicofast
Thank you, for all the replies :D