Adding a Constant Footer to Every File

You can write mod_perl modules that process files, like CGI file filters. Because interpreter is embedded in server, there's almost no overhead.

srm.conf Entry

To modify all files located in the footer/ subdirectory of document tree:
  <Location /footer>
    SetHandler perl-script
    PerlHandler Apache::Footer
  </Location>
To modify all files with extension .footer:
  AddType text/html .footer
  <Files ~ "\.footer$">
     SetHandler  perl-script
     PerlHandler Apache::Footer
  </Files>

Script III.2.1 Apache::Footer

 package Apache::Footer;
 # file Apache::Footer.pm

 use strict vars;
 use Apache::Constants ':common';
 use IO::File;

 sub handler {
     my $r = shift;
     return DECLINED unless $r->content_type() eq 'text/html';
     my $file = $r->filename;
     return DECLINED unless $fh=IO::File->new($file);
     my $modtime = localtime((stat($file))[9]);
     my $footer=<<END;
 <hr>
 © 1998 <a href="http://www.ora.com/">O\'Reilly & Associates</a><br>
 <em>Last Modified: $modtime</em>
 END
 ;
     $r->send_http_header;
    
     while (<$fh>) {
         s!(</BODY>)!$footer$1!oi;
     } continue {
	 $r->print($_);
     }

     return OK;
 }

 1;

What it Looks Like

The unfiltered document:
http://localhost/conference/footer_test.html

Under the control of Apache::Footer:
http://localhost/footer/footer_test.html

<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Mon Aug 17 10:48:56 EDT 1998