If you are running Apache and can access .htaccess, you can otherwise look at @Lock's answer
prepend.php: <?php echo "<p>this is the prepended file</p>\n"; main.php: <?php echo "<p>this is the main file</p>\n"; append.php: <?php echo "<p>this is the appended file</p>\n";
And add prepend.php and add append.php using the instructions below, when main.php is called, the following will be output from the script:
<p>this is the prepended file</p> <p>this is the main file</p> <p>this is the appended file</p>
And add prepend.php and add append.php using the instructions below, when main.php is called, the following will be output from the script:
<p>this is the prepended file</p> <p>this is the main file</p> <p>this is the appended file</p>
Preparation script
To add a file so that it is parsed before the main script, add the following parameter to the .htaccess file, php.ini (which, of course, will affect all websites) or config:
php_value auto_prepend_file prepend.php
The path does not need to be included, but if it is not, it will use the include path to find it. This can lead to the error "Warning: Unknown: Could not open stream: there is no such file or directory in Unknown on line 0" if there is no copy of this directory or the directory in which the script is located in this path. it is best to have the full path to the previously added file. Adding a script
This is pretty much the same as adding a script and the same notes apply. The way to add a file is as follows:
php_value auto_append_file append.php
Cancel setting, so nothing added or added
If you need to override the existing auto_append_file or auto_prepend_file parameter, you can do this by setting the value to none as follows:
php_value auto_prepend_file none php_value auto_append_file none
This can be useful if you want .htaccess to install the append / prepend file at the root level of the website, but then you want some particular subdirectory not to add or add. You will create a new .htaccess file in this subdirectory that does not install them as described above.
Source: http://www.electrictoolbox.com/php-automatically-append-prepend/