Managing PHP include paths on shared hosts

Most shared hosts don't allow you to modify the include paths of PHP files. Further, they don't allow you to place include files and configuration files outside the document root (which poses a major security risk). To manage include paths without stumbling on some "no such file or directory" PHP error, you can use the following solution:

require_once($_SERVER['DOCUMENT_ROOT'] . 'directory/includefile.php');

This way you can call your includes on every single level of your directory structure. I've tested it on my main site and it works well, though I'm aware of the security implications of such a solution. Anyway, remember that most shared hosts don't allow you to modify Apache's configuration neither with an .htaccess file. Oh well...

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.