Zend - The PHP Company




Miscellaneous

Add Code


A better auto prepend/append  

Type: code fragment
Added by: mbroome
Entered: 02/03/2000
Last modified: 08/12/1999
Rating: **** (14 votes)
Views: 14641
A clean way to add a header and/or footer to pages automatically.


To include a header or footer in scripts automatically, if you have access to apache's config files, you can add something like:

php3_auto_prepend_file /path/to/include/prepend.php3
php3_auto_append_file /path/to/include/append.php3

(If you don't have access to the config files but can use .htaccess files, put the above lines in that file)

Put the following code in the prepend.php3 file listed above.  Make a copy of that named append.php3 and change the header.php3 to footer.php3 in the file.

<?
$prepend_dir
=dirname($SCRIPT_FILENAME);
if(
file_exists("$prepend_dir/header.php3")){
   include(
"$prepend_dir/header.php3");
}
/*
 * Uncomment the next few lines to add a header if
 * there is no header.php3 in the current directory
 */
//else{
//   include("/path/to/default/header.php3");
//}
?>

Now you can just put a header.php3 or footer.php3 file in any directory you want and it will be included before/after any script that is called in that directory.  Do make sure of permissions of the directories you do with with since if anyone can put a file named header.php3 or footer.php3 into the directory with your scripts, the file will get included automatically.


Usage Example




Rate This Script





Search



This Category All Categories