1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
>
> Is it possible to do a server-side include such as the following:
> <!--#echo var="LAST_MODIFIED"-->
> ?
>
> I've tried it numerous ways and failed every time -- so I figured it was
> time for a definative answer. I can certainly live without them but they
> would be nice to have.
>
This is done with a server side include that executes a program. To
see this example in action try
<URL:http://hopf.math.nwu.edu/docs/examples/>
Here is an example of how to use scripts as server side includes.
This is not a CGI program, but something similar could be done with
CGI. Assuming that the script counter (listed below) is in the same
directory as foo.html put something like
File=foo.html
Includes=!counter
in your index file. And put
<!-- #include -->
on a line with no leading whitespace in the file foo.html. The
program counter gives the current count of accesses to this page and
also prints the last-modified date. It should be easy to modify for
your needs.
There are a couple of permissions issues. The user id under which the
server runs (e.g. "nobody") must have permission to execute counter
and to read and write the file foo.cnt.
Here is the perl program counter::
%%%%%%%%%%%%%%%%%% Cut here %%%%%%%%%%%%%
#!/usr/local/bin/perl
require "stat.pl";
require "ctime.pl";
# This perl script counts accesses to a file foo.html and prints
# the last modified date for that file. Set the variable $file
# to the complete path of the file whose accesses you want to count.
# $countfile is a file which will contain the current count. The complete
# filename must be given for it too. A careful version of this script
# would do file locking since multiple processes might be trying to
# update $countfile simultaneously. Note that the WN user id (usually
# "nobody") must have write permission for this file.
$file = "/complete/system/path/to/foo.html";
$countfile = "/complete/system/path/to/foo.cnt";
&Stat( $file);
open( COUNT, "<$countfile" ) || die "Can't open file: $! for reading";
$count = <COUNT>;
close( COUNT);
$count++;
print "You are viewer number <b>", $count, "</b> to see this page. <p>\n";
print "It was last modified <b>", &ctime($st_mtime), "</b> <p>\n";
open( COUNT, ">$countfile" ) || die "Can't open file: $! for writing";
print COUNT $count, "\n";
close (COUNT);
|