-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvcount.pl
68 lines (48 loc) · 1.34 KB
/
vcount.pl
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
#!/usr/bin/perl -T
=pod
=head1 NAME
vcount.pl - Visitor counter
=head1 SYNOPSIS
<IMG SRC="http://www.server.com/cgi-bin/vcount.pl">
=head1 DESCRIPTION
The I<vcount.pl> creates an image which can be used as a visitor counter.
This script is not called directory but used to create an counter image
to be embedded in a web page.
The file I</var/visit/vcount.num> contains the visitor counter.
=head1 AUTHOR
Steve Oualline, E<lt>[email protected]<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
use strict;
use warnings;
use GD;
# The file containing the visitor number
my $num_file = "/var/visit/vcount.num";
# Number to use for counter
my $num = 0;
if (-f $num_file) {
if (open IN_FILE, "<$num_file") {
$num = <IN_FILE>;
chomp($num);
close(IN_FILE);
}
}
print "Content-type: image/png\n\n";
my $font = gdGiantFont;
my $char_x = $font->width;
my $char_y = $font->height;
my $picture_x = (1 + $char_x) * length($num) + 1;
my $picture_y = (1 + $char_y);
my $image = new GD::Image($picture_x, $picture_y);
my $background = $image->colorAllocate(0,0,0);
$image->transparent($background);
my $red = $image->colorAllocate(255,0,0);
$image->string($font, 0, 0, $num ,$red);
print $image->png;
++$num;
if (open OUT_FILE, ">$num_file") {
print OUT_FILE $num;
}
close OUT_FILE;