Her er et lille script.....
#!/usr/bin/perl
#############################################################################################
# This script logs visitors to web pages. It can be used as either a SSI, or #
# can be called from a link. To use as a SSI, the $SSI variable must be set to 1. #
# Conversly, to have it be called from links, have $SSI set to 0. #
# To call this script from a link it should have this syntax: #
# <a href=\"/pathToScript/logger.pl?dest=http://yourDomain.com/wherever\">Click Here</a> #
# #
# After the logging is done, it will redirect to the page you have after the ?dest= #
# Log format can be changed, but by default it is like: #
# #
# Date - IP - Host - Browser - Where they are going - Where they came from #
#############################################################################################
# This script may be modified at will. If you do anything cool with it, please let me know. #
# Do not sell this script without my permission and always leave the comments. #
# Kevin Meltzer 3/12/97 kmeltz@cris.com |
www.ctcom.com/~kmeltz #
#############################################################################################
# Set variables
$SSI = 2; # 0 - Used from link
# 1 - Used as Server Side Include
# 2 - Used from <img> tag
$logfile = \"logger.log\"; # Path to your log file, must be chmod 666
$ip = $ENV{\'REMOTE_ADDR\'};
$browser = $ENV{\'HTTP_USER_AGENT\'};
$referer = $ENV{\'HTTP_REFERER\'};
$here = $ENV{\'DOCUMENT_URI\'};
@digits = split (/\\./, $ip);
$address = pack (\"C4\", @digits);
$host = gethostbyaddr ($address, 2);
# From Link
if ($SSI eq 0) {
&parse_query;
&clean;
$dest = $query{\'dest\'};
&write_file;
&redirect;
}
# From SSI
if ($SSI eq 1) {
&write_file;
}
# From <img> tag
if ($SSI eq 2) {
&parse_query;
&clean;
$this = $query{\'dest\'};
&write_file;
&show_img;
}
################################################
# Parse the query then clean it up for our uses
################################################
sub parse_query {
@query_strings = split(\"&\", $ENV{\"QUERY_STRING\"});
foreach $q (@query_strings) {
($attr, $val) = split(\"=\", $q);
$query{$attr} = $query{$attr}.\" \".$val;
}
}
sub clean {
if ($query{\'dest\'} =~ /\\/$/) {
chop($query{\'dest\'});
}
#$query{\'dest\'} =~ s/http\\:\\/\\///g;
#$query{\'dest\'} =~ s/\\//_\\|_/g;
}
################################################
# Go!
################################################
sub redirect {
print \"Location: $dest\\n\\n\";
}
################################################
# Write information to the log
################################################
sub write_file {
if (! (-f \"$logfile\")) {
open (LOG, \">$logfile\");
close LOG;
}
&date;
open (LOG,\">>$logfile\") || die \"Can\'t write to log file\";
if ($SSI eq 0) {
print LOG \"$date - $ip - $host - $browser - $dest - $referer\\n\";
}
elsif ($SSI eq 1) {
print LOG \"$date - $ip - $host - $browser - $here - $referer\\n\";
}
else {
print LOG \"$date - $ip - $host - $browser - $this - $referer\\n\";
}
close LOG;
} # end sub
#################################################
# Get date and show it in mm/dd/yy format
#################################################
sub date {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = (\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\");
$date = \"@months[$mon]/$mday/$year\";
}
#################################################
# Subroutine to return a 1-pixel transparent gif
#################################################
sub show_img {
$! = 1;
$| = 1;
print \"Content-type: image/gif\\n\\nGIF89a\\1\\0\\1\\0\\200\\0\\0\\0\\0\\0\\0\\0\\0!\\371\\4\\1\\0\\0\\0\\0,\\0\\0\\0\\0\\1\\0\\1\\0\\0\\2\\2D\\1\\0\\n\";
}
# End