This needs to be done with a server-side language such as PHP. In PHP, the code would run as follows:
PHP Code:
<?php
// clickcounter.inc.php
$newline = "\n"; // Newline symbol for the server. Likely values are "\n" for *n?x or "\r\n" for Windows.
$filename = "clickcount.dat"; // Name of the file in which to store number of clicks.
// Function to get the number of registrants.
function getClicks() {
global $filename, $newline;
return file_exists($filename) ? implode(file($filename), $newline) + 0 : 0;
}
// Function to increment the number of registrants.
function incClicks() {
global $filename, $newline;
$clickcount = getClicks();
$clickcount++;
$file = fopen($filename, "w");
fputs($file, $clickcount);
fclose($file);
}
?>
PHP Code:
<!-- Top of the page on which to display the number of clicks: -->
<?php include("clickcounter.inc.php"); ?>
<!-- Where you want to display the number of views: -->
<p>Number of views: <?php echo(getClicks()); ?></p>
PHP Code:
<?php
// This page instead of the image:
include("clickcounter.inc.php");
$image = "myimage.png";
header("Content-Type: " . mime_content_type($image));
incClicks();
readfile($image);
?>
Bookmarks