Viewing a single comment thread. View all comments

z3d wrote (edited )

With the default I2P webserver (Jetty), assuming you have perl installed, you can run perl scripts from eepsite/cgi-bin. Something like the following will provide a basic pagecounter when embedded in a iframe:

#!/usr/bin/perl

use strict;
use warnings;

# File to store the page counter
my $counterFile = "counter.txt";

# Read current counter value from file
my $counter = 0;
if (-e $counterFile) {
open(my $fh, '<', $counterFile);
$counter = <$fh>;
chomp($counter);
close($fh);
}

# Increment the counter
$counter++;

# Save updated counter value to file
open(my $fh, '>', $counterFile);
print $fh $counter;
close($fh);

# Generate HTML page counter span
print "Content-Type: text/html\n\n";
print "<span id=\"counter\">$counter</span>\n";
4

not_bob wrote

Very good, but it should really use flock for file locking to prevent possible race conditions.

But, so long as the site isn't getting a really large number of hits, this is unlikely to be a problem even if you don't use it.

1