Page 1 of 1

php.ini include_path Issue

Posted: Sat Jan 17, 2009 9:50 am
by zrattner
Hi,

I am working on a somewhat large web site, and I would like to keep my include files out of the web root for security's sake. I have all of my website code in a directory inside the web root, and the include directory one level above the web root.

So, if I'm at example.com/dir1/index.php and I would like to include a file from the include directory, I would use

Code: Select all

require_once('../../include/mysql/file.php');
This much is working. However, I would like to set up php.ini so I can leave out the '../../include' in the require statements. That is, I would like this code:

Code: Select all

require_once('mysql/file.php');
to really execute this statement:

Code: Select all

require_once('../../include/mysql/file.php);
Additionally, I would like to have php.ini handle multiple level directories. So, if I was to be at example.com/dir1/dir2/file.php, I would still like to be able to call

Code: Select all

require_once('mysql/file.php');
. I've tried adding this to my php.ini file, but it didn't work:

Code: Select all

:../../Include
I'm hosted on a Linux environment, if that helps anything.

I would greatly appreciate any help you could give. Thanks,
Zach

Re: php.ini include_path Issue

Posted: Sat Jan 17, 2009 10:00 am
by Burrito
I'm not sure you can add multiple include directives in your php.ini...might be able to, but I'm just not sure 8O

you could use an .htaccess to define these 'virtual directories' or create a set of local variables with your paths.

edit:
PHP Manual wrote: Specifies a list of directories where the require(), include(), fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.

Re: php.ini include_path Issue

Posted: Sat Jan 17, 2009 10:43 am
by zrattner
Thanks Burrito, turns out it was as simple as:

Code: Select all

.:Include/:../Include/:../../Include/
Basically, start the string with a period, then put each path to check between colons.