php.ini include_path Issue

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
zrattner
Forum Newbie
Posts: 2
Joined: Sat Jan 17, 2009 9:42 am

php.ini include_path Issue

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: php.ini include_path Issue

Post 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.
zrattner
Forum Newbie
Posts: 2
Joined: Sat Jan 17, 2009 9:42 am

Re: php.ini include_path Issue

Post 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.
Post Reply