PHP: Pre/Post processing

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

PHP: Pre/Post processing

Post by markl999 »

If every page requires common code to be included, for example a common header and footer then rather than include 'header.php' and/or include 'footer.php' on evry page you can make uses of PHP's auto_prepend_file and auto_append_file.

These directives can be set either in http.conf (inside a vhost) or in a .htaccess file.

Example:

Code: Select all

php_value auto_prepend_file prepend.php
Inside prepend.php you could initialise objects, such a logging objects, check user permissions for the requested page and also do your include 'header.php' too. auto_append_file is the same but it is 'called' after you script. So the flow goes..

auto_prepend_file first.
you script next.
auto_append_file last.
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

It's not simple to disable for specific files. If you're serving up binary data, you might want to turn it off. Doing all this in PHP is probably a lot more efficient, and safer for your server (less .htaccess hacking).
Post Reply