Set PHP Include Path in htaccess

If you do not want to change the include_path directories (or you don’t have access to php.ini) you can still set the include_path value within your root .htaccess file.

Update/Create /doc_root/.htaccess

Unix/Linux Servers

php_value include_path "/path/to/include"

Windows Servers

php_value include_path "C:/path/to/include"

PHP

To call the include within PHP do the following:

require_once('file.php');

The file above is in /doc_root/include/file.php

Options

Multiple include directories

If you have multiple include directories you can chain them with the separator for your OS, : (*nix), ; (Windows).

php_value include_path "/path/to/include:/path/to/include2"

Call files outside include directory

You can also traverse your directory structure if you need to call a file that is outside of the include_path.

file.php in /doc_root/include/file.php

require_once('./include/file.php');

file.php in /doc_root/test/file.php

require_once('./test/file.php');

file.php in /test/file.php, Outside, up one level from /doc_root

require_once('../test/file.php');


Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

Tags: , ,

Leave a Reply





Donate

If you found this article useful and would like to see more like it this please consider making a donation.

Sponsors