#15 Visitor Counter

This program lets someone know how many times a web page has been visited.

The Code

 1 #!/usr/bin/perl -T 2 use strict; 3 use warnings; 4 use GD; 5 6 # The file containing the visitor number 7 my $num_file = "/var/visit/vcount.num"; 8 9 # Number to use for counter 10 my $num = 0; 11 if (-f $num_file) { 12 if (open IN_FILE, "<$num_file") { 13 $num = <IN_FILE>; 14 chomp($num); 15 close(IN_FILE); 16 } 17 } 18 19 print "Content-type: image/png\n\n"; 20 21 my $font = gdGiantFont; 22 my $char_x = $font->width; 23 my $char_y = $font->height; 24 25 my $picture_x = (1 + $char_x) * length($num) + 1; 26 my $picture_y = (1 + $char_y); 27 28 my $image = new GD::Image($picture_x, $picture_y); 29 my $background = $image->colorAllocate(0,0,0); ...

Get Wicked Cool Perl Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.