auto_prepend_file
You learn new things everyday, even in areas where you are vastly familiar. I remember discovering the include_path
php directive a few years ago and how that made programming my sites so much easier. You didn’t need to worry about how deep into a directory structure you were, the include
and require
statements would find the library files you were looking for. Definitely made ones code more portable — something that my early work was not.
I should have read that list of directives more carefully at that point, because nestled among the useless and benign were two gems: auto_prepend_file
and auto_append_file
which will make my life that much simpler. These directives allow you to specify per directory with the .htaccess
file any scripts that you want included before and/or after the main page executes. Not only does this mean you can have your libraries in one convenient location, but you don’t need to include them manually on each page. According to the manual, these specified files are included using the include()
call. So you may not want to directly include any important libraries — instead include a file which in turn calls require_once()
for each of your important libraries.
The format of the entry for these directive in the htaccess file is as follows:
php_value auto_prepend_file "/path/to/file.inc"