In the php.ini file, you can set the variables auto_prepend_file and auto_append_file, so that php will automatically add a file before and after it parses your php script.
I’m going to use an apache .htaccess file to add these files, so that I can log page hits into a mysql database automatically – I use the prepend file to set a variable to the current timestamp (with milliseconds) and the append file to work out how long the script took to execute, and to add it in to the database/log. You could also use it for setting custom error handling functions, for example.
To do this, create a file called “.htaccess” (windows won’t let you save this, unless you put in the quote marks). In this file, type…
<IfModule mod_php4.c> php_value auto_prepend_file "/home/sites/site57/web/test/prepend/prepend.php" php_value auto_append_file "/home/sites/site57/web/append.php" </IfModule>
This file will work on the whole directory tree below it’s position.